export interface User {
    uuid: string;
    id: number;
    mobile_number: string;
    name?: string | null;
    first_name?: string | null;
    last_name?: string | null;
    email: string | null;
    roles: string[];
    is_active: boolean;
    created_at: string;
    updated_at?: string;
}

export interface UserProfile {
    uuid: string;
    blood_group: string | null;
    weight: number | null;
    height: number | null;
    diseases: string | null;
    medications: string | null;
    allergies: string | null;
    insurance_type: string | null;
}

export interface Doctor {
    uuid: string;
    first_name: string;
    last_name: string;
    medical_code: string;
    gender: "male" | "female";
    degree: string;
    bio: string | null;
    profile_image: string | null;
    is_active: boolean;
    specialties: Specialty[];
    created_at: string;
}

export interface Clinic {
    uuid: string;
    name: string;
    phone: string | null;
    logo: string | null;
    is_active: boolean;
    doctors_count: number;
    created_at: number;
    owner_mobile: string | null;
}

export interface ClinicDetail {
    id: string;
    uuid: string;
    name: string | null;
    title: string | null;
    is_active: boolean;
    phone: string | null;
    phone_number: string | null;
    logo: string | null;
    clinic_logo: string | null;
    caption: string | null;
    images_clinic: { url: string; fid?: number }[];
    social_media: {
        instagram: string | null;
        telegram: string | null;
        aparat: string | null;
        youtube: string | null;
        linkedin: string | null;
    } | null;
    specialties: { id: string; uuid: string; name: string }[];
    services: { id: string; uuid: string; name: string }[];
    list_bime: { id: string; uuid: string; name: string }[];
    doctors: number;
    city: { id: string; name: string }[];
    state: { id: string; name: string }[];
    location: string | null;
    map: { latitude: string | null; longitude: string | null };
    "24_7": boolean;
    field_working_days: string | null;
}

export type AppointmentStatus =
    | "pending"
    | "confirmed"
    | "completed"
    | "cancelled_by_doctor"
    | "cancelled_by_user"
    | "no_show"
    | "expired";

export interface Appointment {
    uuid: string;
    patient_name: string;
    patient_mobile: string;
    doctor_uuid: string;
    doctor_name: string;
    slot_start: number;
    slot_end: number;
    appointment_date: string;
    appointment_time: string;
    end_time: string;
    status: AppointmentStatus;
    version: number;
    created_at: string;
}

export type PaymentStatus =
    | "pending"
    | "success"
    | "failed"
    | "canceled"
    | "refunded";
export type PaymentGateway = "mellat" | "sep";

export interface Payment {
    uuid: string;
    amount: number;
    status: PaymentStatus;
    gateway: PaymentGateway;
    ref_id: string | null;
    card_pan?: string | null;
    refunds?: { amount: number; ref: string; at: number }[];
    patient_mobile: string;
    appointment_uuid: string | null;
    paid_at: string | null;
    created_at: string;
    order_id?: string;
    patient_name?: string | null;
    type?: string;
}

export type SettlementStatus = "pending" | "approved" | "rejected";

export interface Settlement {
    uuid: string;
    representation_name: string;
    amount: number;
    status: SettlementStatus;
    bank_card: string | null;
    bank_name: string | null;
    reject_reason: string | null;
    requested_at: string;
    processed_at: string | null;
}

export interface Representation {
    id: number;
    uuid: string;
    full_name: string;
    domain?: string | null;
    is_global?: boolean;
    mobile_number: string | null;
    city_id: number | null;
    city_ids?: number[];
    cities?: { id: number; name: string }[];
    city: string | null;
    commission_percent: number;
    bank_account: { card?: string; bank_name?: string; iban?: string } | null;
    wallet_balance?: number;
    doctor_count?: number;
    appointment_count?: number;
    active?: boolean;
    is_active?: boolean;
    created_at: string;
}

export interface Comment {
    uuid: string;
    patient_name: string;
    doctor_name: string;
    title: string;
    body: string;
    is_approved: boolean;
    created_at: string;
}

export interface Rating {
    uuid: string;
    patient_name: string;
    doctor_name: string;
    diagnosis_accuracy: number;
    skill: number;
    behavior: number;
    cleanliness: number;
    waiting_time: number;
    overall: number;
    created_at: string;
}

export type SmsTemplateStatus = "draft" | "pending" | "approved" | "rejected";

export interface SmsTemplate {
    uuid: string;
    name: string;
    body: string;
    provider_code: string | null;
    status: SmsTemplateStatus;
    admin_note: string | null;
    created_at: string;
}

export interface SmsLog {
    uuid: string;
    recipient: string;
    message: string;
    status: "queued" | "sent" | "failed";
    provider: string;
    tag: string;
    template: string | null;
    sent_at: string | null;
    created_at: string;
}

export interface AppLog {
    id: number;
    level: string;
    message: string;
    context: string | null;
    channel: string | null;
    path: string | null;
    created_at: number;
}

export interface SmsMessageText {
    tag: string;
    title: string;
    body: string;
    variables: string[];
    kavenegar_template: string | null;
    token_map: Record<string, string>;
    updated_at: number | null;
}

export interface Province {
    id: number;
    uuid: string;
    name: string;
    status: number;
    weight: number;
}

export interface City {
    id: number;
    uuid: string;
    name: string;
    site_name?: string | null;
    title?: string | null;
    status: number;
    weight: number;
    province_id: number | null;
    representation_id?: number | null;
    contact_phone?: string | null;
    email?: string | null;
    description?: string | null;
    slogan?: string | null;
    domain?: string | null;
    keywords?: string | null;
    footer_description?: string | null;
    social_media?: Record<string, string> | null;
    logo_url?: string | null;
}

export interface SpecialtyFull {
    id: number;
    uuid: string;
    name: string;
    slug: string;
    status: number;
    weight: number;
    parent_id: number | null;
}

export interface DoctorService {
    id: number;
    uuid: string;
    name: string;
    slug: string;
    status: number;
    weight: number;
    specialty_id: number | null;
}

export interface Insurance {
    id: number;
    uuid: string;
    name: string;
    type: "basic" | "supplementary";
    logo_url: string | null;
    status: number;
}

export interface Tag {
    id: number;
    uuid: string;
    name: string;
    slug: string;
    status: number;
}

export interface Blog {
    uuid: string;
    title: string;
    slug: string;
    summary: string | null;
    body: string;
    image_url: string | null;
    status: "draft" | "published";
    author?: { uuid: string; name: string } | null;
    tags: string[];
    created_at: string;
    updated_at?: string;
}

export interface Secretary {
    uuid: string;
    user_name: string;
    mobile_number: string;
    doctor_name: string;
    doctor_uuid: string;
    is_active: boolean;
    permissions: SecretaryPermissions;
    created_at: string;
}

export interface SecretaryPermissions {
    appointments: {
        view: boolean;
        create: boolean;
        cancel: boolean;
        update_status: boolean;
    };
    addresses: {
        view: boolean;
        create: boolean;
        update: boolean;
        delete: boolean;
    };
    clinic_info: {
        view: boolean;
        update: boolean;
    };
    insurances: {
        view: boolean;
        create: boolean;
        update: boolean;
        delete: boolean;
    };
}

export interface Specialty {
    id?: number;
    uuid: string;
    name: string;
    slug?: string;
}

export interface ClinicStaff {
    uuid: string;
    full_name: string;
    phone: string | null;
    job_title: string | null;
    address: string | null;
    national_code: string | null;
    active: boolean;
    created_at: number;
}

export interface SubscriptionPlan {
    uuid: string;
    name: string;
    level: number;
    max_secretaries: number;
    features: Record<string, boolean>;
    active: boolean;
    periods: SubscriptionPeriod[];
}

export interface SubscriptionPeriod {
    uuid: string;
    label: string;
    duration_months: number;
    price_rials: number;
    is_trial: boolean;
}

export interface MySubscriptionData {
    subscription: {
        plan: {
            name: string;
            level: number;
            max_secretaries: number;
            features: Record<string, boolean>;
        };
        period?: { label: string; duration_months: number };
        is_trial: boolean;
        starts_at?: number;
        expires_at?: number | null;
        days_remaining?: number;
    } | null;
    used_trial: boolean;
    /** پلن مؤثر: پلن اشتراک فعال یا پلن پیش‌فرض free در نبود اشتراک. */
    effective_plan: {
        name: string;
        level: number;
        max_secretaries: number;
        features: Record<string, boolean>;
    } | null;
}
/** @deprecated use MySubscriptionData */
export interface MySubscription {
    plan: { name: string; level: number; features: Record<string, boolean> };
    period?: { label: string; duration_months: number };
    is_trial: boolean;
    starts_at?: number;
    expires_at?: number | null;
    used_trial: boolean;
    days_remaining?: number;
}

export interface ServiceSection {
    uuid: string;
    name: string;
    active: boolean;
}

export interface ServiceItem {
    uuid: string;
    name: string;
    price_rials: number;
    staff: { uuid: string; full_name: string } | null;
    active: boolean;
    insurance_covered?: boolean;
    insurance_price_rials?: number | null;
    duration_minutes?: number | null;
}

export interface SmsWalletBalance {
    balance_rials: number;
    sms_price_rials: number;
    estimated_sms_count: number;
}

export interface SmsWalletLog {
    uuid: string;
    type: "credit" | "debit";
    amount_rials: number;
    description: string;
    created_at: number;
}

export interface SmsSettings {
    reminder_enabled: boolean;
    reminder_hours_before: number;
    post_visit_enabled: boolean;
    post_visit_text: string | null;
    post_visit_text_pending?: string | null;
    post_visit_text_status?: "none" | "pending" | "approved" | "rejected";
    post_visit_text_reject_reason?: string | null;
}

export interface PatientProfile {
    full_name?: string | null;
    name?: string | null;
    family?: string | null;
    fathers_name?: string | null;
    national_code?: string | null;
    gender?: string | null;
    date_of_birth?: number | null;
    blood_type?: string | null;
    marital_status?: string | null;
    education?: string | null;
    field_of_study?: string | null;
    job?: string | null;
    address?: string | null;
    province_id?: number | null;
    city_id?: number | null;
    postal_code?: string | null;
    referral_source?: string | null;
    description?: string | null;
    home_phone?: string | null;
    work_phone?: string | null;
    mobile?: string | null;
    basic_insurance_id?: number | null;
    basic_insurance_name?: string | null;
    supplementary_insurance_id?: number | null;
    supplementary_insurance_name?: string | null;
}

/** بدنه‌ی PATCH /api/v1/patient/{uuid} — تمام کلیدها اختیاری (partial update). */
export interface PatientProfileUpdate {
    name?: string;
    mobile?: string;
    national_code?: string;
    gender?: string | null;
    fathers_name?: string | null;
    date_of_birth?: number | null;
    marital_status?: string | null;
    education?: string | null;
    field_of_study?: string | null;
    job?: string | null;
    basic_insurance_id?: number | null;
    province_id?: number | null;
    city_id?: number | null;
    home_phone?: string | null;
    address?: string | null;
    postal_code?: string | null;
    referral_source?: string | null;
    description?: string | null;
}

export interface PatientRecord {
    uuid: string;
    entity_type: string;
    entity_id: number;
    user_uuid?: string;
    user_name?: string | null;
    user_mobile?: string | null;
    user_national_code?: string | null;
    created_at: number;
    profile?: PatientProfile | null;
}

export interface SessionServiceLine {
    uuid: string;
    service_item_uuid: string;
    service_name: string;
    staff_uuid: string | null;
    staff_name: string | null;
    price_rials: number;
    quantity: number;
    line_total_rials: number;
    created_at: number;
}

export interface PatientAppointment {
    uuid: string;
    starts_at: number;
    ends_at: number | null;
    status: string;
    doctor_name: string | null;
    service_name: string | null;
    price_rials: number | null;
    created_at: number;
}

export interface PatientSession {
    uuid: string;
    record_uuid: string;
    appointment_uuid: string | null;
    doctor_uuid?: string | null;
    doctor_name?: string | null;
    insurance_base_id: number | null;
    insurance_supplementary_id: number | null;
    visit_price_rials: number;
    base_insurance_discount_percent: string;
    supplementary_discount_percent: string;
    services_total_rials: number;
    final_price_rials: number;
    payment_method: string;
    is_paid?: boolean;
    services?: SessionServiceLine[];
    invoice_uuid?: string | null;
    invoice_status?: string | null;
    patient_debt_rials?: number;
    notes: string | null;
    created_at: number;
    updated_at: number;
}
