/** A status as the customer reads it, rather than the desk's internal name. */
export type CustomerTicketStatus = {
    value: string;
    label: string;
    description: string;
    tone: string;
    is_finished: boolean;
};

export type CustomerJobLink = {
    id: number;
    job_number: string;
};

export type CustomerTicket = {
    id: number;
    display_number: string;
    issue: string;
    status: CustomerTicketStatus;
    reported_at: string | null;
    last_update_at: string | null;
    job: CustomerJobLink | null;
    needs_your_reply: boolean;
};

export type CustomerTicketMessage = {
    id: number;
    body_html: string;
    from_customer: boolean;
    author: string;
    posted_at: string | null;
};

export type CustomerTicketAttachment = {
    id: number;
    name: string;
    human_size: string;
    is_image: boolean;
    url: string;
};

export type CustomerTicketProgress = {
    key: string;
    label: string;
    description: string;
    state: 'done' | 'current' | 'todo';
};

export type CustomerJob = {
    id: number;
    job_number: string;
    title: string;
    status_label: string;
    install_date: string | null;
    address: string | null;
    system_size_kw: number | null;
};

export type CustomerJobDetail = CustomerJob & {
    site: {
        label: string | null;
        address_line1: string;
        suburb: string;
        state: string;
        postcode: string;
        nmi: string | null;
        meter_number: string | null;
    } | null;
    system: {
        system_size_kw: number | null;
        panel_count: number | null;
        panel: string | null;
        inverter: string | null;
        inverter_serial: string | null;
        battery: string | null;
        battery_capacity_kwh: number | null;
        export_limit_kw: number | null;
    };
    connected: boolean;
    installed_on: string | null;
    tickets: CustomerTicket[];
};

export type CustomerTicketDetail = CustomerTicket & {
    description_html: string;
    resolution_html: string | null;
    progress: CustomerTicketProgress[];
    dates: {
        reported_at: string | null;
        acknowledged_at: string | null;
        resolved_at: string | null;
        closed_at: string | null;
    };
    attachments: CustomerTicketAttachment[];
    messages: CustomerTicketMessage[];
    job: CustomerJob | null;
};

export type CustomerAccountSummary = {
    id: number;
    name: string;
    customer_number: string;
    email: string | null;
    phone: string | null;
};

export type CustomerAccount = {
    id: number;
    name: string;
    email: string;
    phone: string | null;
    customer: CustomerAccountSummary | null;
};

export type CustomerIssueCategory = {
    value: string;
    label: string;
    description: string;
    hazardous: boolean;
};

export type CustomerSession = {
    id: number;
    name: string;
    email: string;
    verified: boolean;
};

/** One field a customer asked to change, as it was and as they want it. */
export type CustomerChangeRow = {
    field: string;
    label: string;
    from: string | null;
    to: string | null;
};

/**
 * A change waiting on our team, or one they have already answered. The same
 * shape is shown to the customer and in the staff review queue.
 */
export type CustomerChangeRequest = {
    id: number;
    status: {
        value: string;
        label: string;
        tone: string;
        is_pending: boolean;
    };
    changes: CustomerChangeRow[];
    customer_note: string | null;
    submitted_at: string | null;
    submitted_by: string | null;
    customer: {
        id: number;
        name: string;
        customer_number: string;
        email: string | null;
        phone: string | null;
    } | null;
    reviewer: { id: number; name: string } | null;
    reviewed_at: string | null;
    review_note: string | null;
};

/** The customer record as it stands, which is what the form starts from. */
export type CustomerProfileDetails = {
    first_name: string | null;
    last_name: string | null;
    email: string | null;
    phone: string | null;
    alternate_phone: string | null;
    billing_address_line1: string | null;
    billing_address_line2: string | null;
    billing_suburb: string | null;
    billing_state: string | null;
    billing_postcode: string | null;
};
