/**
 * The installer register's shapes, mirroring App\Support\Presenters\InstallerPresenter.
 */

/** Where a credential stands today, worked out on the server. */
export type CredentialStatus = 'current' | 'expiring' | 'expired' | 'missing';

export type InstallerCredential = {
    number: string | null;
    expiry: string | null;
    status: CredentialStatus;
};

export type InstallerComplianceIssue = {
    key: string;
    label: string;
    date: string;
    /** Negative once the date has passed. */
    days: number;
    expired: boolean;
};

export type InstallerSummary = {
    id: number;
    installer_number: string;
    name: string;
    business_name: string | null;
    display_name: string;
    abn: string | null;
    email: string | null;
    phone: string | null;
    suburb: string | null;
    state: { value: string; label: string } | null;
    service_area: string | null;
    electrical_contractor: InstallerCredential;
    saa: InstallerCredential;
    insurance: InstallerCredential;
    compliance: {
        status: 'expired' | 'expiring' | 'current' | 'none';
        label: string;
        issues: InstallerComplianceIssue[];
    };
    documents_received: boolean;
    is_active: boolean;
    verified_at: string | null;
    created_at: string | null;
};

export type InstallerDetail = InstallerSummary & {
    address: {
        line1: string | null;
        line2: string | null;
        suburb: string | null;
        state: string | null;
        state_label: string | null;
        postcode: string | null;
        one_line: string;
    };
    credentials: Array<{
        key: string;
        label: string;
        number: string | null;
        expiry: string | null;
        status: CredentialStatus | 'current';
        source: string;
    }>;
    cover: {
        public_liability: number | null;
        professional_indemnity: number | null;
    };
    accreditation_classes: string[];
    notes: string | null;
    notes_html: string | null;
    source: string | null;
    created_by: { id: number; name: string } | null;
    updated_by: { id: number; name: string } | null;
    updated_at: string | null;
};

export type InstallerFormOptions = {
    states: Array<{ value: string; label: string }>;
    accreditationClasses: Array<{ value: string; label: string }>;
};
