package com.tt.honeyDue.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ContractorUser(
    val id: Int,
    val username: String,
    @SerialName("first_name") val firstName: String? = null,
    @SerialName("last_name") val lastName: String? = null
)

@Serializable
data class Contractor(
    val id: Int,
    @SerialName("residence_id") val residenceId: Int? = null,
    @SerialName("created_by_id") val createdById: Int,
    @SerialName("added_by") val addedBy: Int,
    @SerialName("created_by") val createdBy: ContractorUser? = null,
    val name: String,
    val company: String? = null,
    val phone: String? = null,
    val email: String? = null,
    val website: String? = null,
    val notes: String? = null,
    @SerialName("street_address") val streetAddress: String? = null,
    val city: String? = null,
    @SerialName("state_province") val stateProvince: String? = null,
    @SerialName("postal_code") val postalCode: String? = null,
    val specialties: List<ContractorSpecialty> = emptyList(),
    val rating: Double? = null,
    @SerialName("is_favorite") val isFavorite: Boolean = false,
    @SerialName("is_active") val isActive: Boolean = true,
    @SerialName("task_count") val taskCount: Int = 0,
    @SerialName("created_at") val createdAt: String,
    @SerialName("updated_at") val updatedAt: String
)

@Serializable
data class ContractorCreateRequest(
    val name: String,
    @SerialName("residence_id") val residenceId: Int? = null,
    val company: String? = null,
    val phone: String? = null,
    val email: String? = null,
    val website: String? = null,
    @SerialName("street_address") val streetAddress: String? = null,
    val city: String? = null,
    @SerialName("state_province") val stateProvince: String? = null,
    @SerialName("postal_code") val postalCode: String? = null,
    val rating: Double? = null,
    @SerialName("is_favorite") val isFavorite: Boolean = false,
    val notes: String? = null,
    @SerialName("specialty_ids") val specialtyIds: List<Int>? = null
)

@Serializable
data class ContractorUpdateRequest(
    val name: String? = null,
    @SerialName("residence_id") val residenceId: Int? = null,
    val company: String? = null,
    val phone: String? = null,
    val email: String? = null,
    val website: String? = null,
    @SerialName("street_address") val streetAddress: String? = null,
    val city: String? = null,
    @SerialName("state_province") val stateProvince: String? = null,
    @SerialName("postal_code") val postalCode: String? = null,
    val rating: Double? = null,
    @SerialName("is_favorite") val isFavorite: Boolean? = null,
    val notes: String? = null,
    @SerialName("specialty_ids") val specialtyIds: List<Int>? = null
)

@Serializable
data class ContractorSummary(
    val id: Int,
    @SerialName("residence_id") val residenceId: Int? = null,
    val name: String,
    val company: String? = null,
    val phone: String? = null,
    val specialties: List<ContractorSpecialty> = emptyList(),
    val rating: Double? = null,
    @SerialName("is_favorite") val isFavorite: Boolean = false,
    @SerialName("task_count") val taskCount: Int = 0
)

// Extension to convert full Contractor to ContractorSummary
fun Contractor.toSummary() = ContractorSummary(
    id = id,
    residenceId = residenceId,
    name = name,
    company = company,
    phone = phone,
    specialties = specialties,
    rating = rating,
    isFavorite = isFavorite,
    taskCount = taskCount
)
