// Member-related TypeScript interfaces

import type { Financing } from './financing';
import type { SavingsAccount } from './savings';

export interface Member {
    id: number;
    legacy_id: string | null;
    branch_id: number | null;
    id_number: string | null;
    id_type: string | null;
    name: string;
    birth_date: string | null;
    birth_place: string | null;
    gender: 'male' | 'female' | null;
    religion: string | null;
    mother_maiden_name: string | null;
    alias_name: string | null;
    marital_status: 'single' | 'married' | 'divorced' | 'widowed' | null;

    // Contact Information
    phone: string | null;
    mobile: string | null;
    email: string | null; // Most members don't have email
    address: string | null;
    address_id_card: string | null;
    village: string | null;
    district: string | null;
    city: string | null;
    province: string | null;
    postal_code: string | null;
    village_relation?: {
        id: string;
        name: string;
    };
    district_relation?: {
        id: string;
        name: string;
    };
    regency_relation?: {
        id: string;
        name: string;
    };
    province_relation?: {
        id: string;
        name: string;
    };

    // Employment Information
    occupation: string | null;
    employer_name: string | null;
    employer_address: string | null;
    business_field: string | null;
    monthly_income: number;
    income_source: string | null;

    // Spouse Information
    spouse_name: string | null;
    spouse_birth_date: string | null;
    wedding_date: string | null;
    spouse_occupation: string | null;

    // Heir Information (Waris)
    heir_name: string | null;
    heir_address: string | null;
    heir_phone: string | null;
    heir_birth_date: string | null;
    heir_gender: 'male' | 'female' | null;
    heir_relationship: string | null;

    // Additional Information
    npwp: string | null;
    is_verified: boolean;
    registration_date: string | null;
    notes: string | null;

    // Metadata
    created_at: string | null;
    updated_at: string | null;
    deleted_at: string | null;
    created_by: number | null;
    updated_by: number | null;

    // Accessor properties
    active_financings_count?: number;

    // Relationships
    roles?: Array<{
        id: number;
        name: string;
    }>;
    branch?: {
        id: number;
        name: string;
    };
    savings_accounts?: SavingsAccount[];
    financings?: Financing[];
}

// export interface Branch {
//     id: number;
//     code: string;
//     name: string;
//     address?: string;
//     city?: string;
//     province?: string;
//     phone?: string;
//     email?: string;
//     is_headquarters: boolean;
//     is_active: boolean;
// }

export interface PaginatedData<T> {
    data: T[];
    current_page: number;
    last_page: number;
    per_page: number;
    total: number;
    from: number | null;
    to: number | null;
    links: {
        url: string | null;
        label: string;
        active: boolean;
    }[];
    prev_page_url: string | null;
    next_page_url: string | null;
}

export interface MemberFilters {
    search?: string;
    branch_id?: string;
    is_verified?: string;
}

export interface MemberSummary {
    member: Member;
    savings: {
        total_accounts: number;
        active_accounts: number;
        total_balance: number;
    };
    financing: {
        total_financings: number;
        active_financings: number;
        total_balance: number;
        overdue_count: number;
    };
}

export type MemberWithBranch = Member & {
    branch?: { id: number; name: string };
};

export interface MemberShowProps {
    member: MemberWithBranch;
    summary?: MemberSummary;
    savings_accounts?: SavingsAccount[];
    financings?: Financing[];
}

export interface MemberDetailProps {
    member: MemberWithBranch;
}

export interface StatsCardProps {
    member: MemberWithBranch;
    summary: MemberSummary;
}
