//! `OData` filter field definitions for Address resources.

use time::OffsetDateTime;
use toolkit_odata_macros::ODataFilterable;
use toolkit_sdk::odata::{FieldRef, Schema};
use uuid::Uuid;

use toolkit_odata::filter::FilterField as _;

/// Address filterable fields schema.
///
/// This struct defines which fields can be used in `OData` $filter queries
/// for address resources. The field names match the wire format.
///
/// Note: Addresses don't currently have list endpoints with `OData` filtering
/// in the REST API, but this schema is provided for consistency and future use.
#[derive(ODataFilterable)]
pub struct AddressQuery {
    #[odata(filter(kind = "Uuid"))]
    pub id: Uuid,

    #[odata(filter(kind = "Uuid"))]
    pub user_id: Uuid,

    #[odata(filter(kind = "Uuid"))]
    pub city_id: Uuid,

    #[odata(filter(kind = "String"))]
    pub street: String,

    #[odata(filter(kind = "String"))]
    pub postal_code: String,

    #[odata(filter(kind = "DateTimeUtc"))]
    pub created_at: OffsetDateTime,
}

/// Type alias for the generated filter field enum.
///
/// This enum is auto-generated by the `ODataFilterable` derive macro
/// and represents all filterable fields for addresses.
pub use AddressQueryFilterField as AddressFilterField;

#[derive(Debug, Clone, Copy)]
pub struct AddressSchema;

impl Schema for AddressSchema {
    type Field = AddressFilterField;

    fn field_name(field: Self::Field) -> &'static str {
        field.name()
    }
}

pub const ADDRESS_ID: FieldRef<AddressSchema, Uuid> = FieldRef::new(AddressFilterField::Id);
pub const ADDRESS_USER_ID: FieldRef<AddressSchema, Uuid> =
    FieldRef::new(AddressFilterField::UserId);
pub const ADDRESS_CITY_ID: FieldRef<AddressSchema, Uuid> =
    FieldRef::new(AddressFilterField::CityId);
pub const ADDRESS_STREET: FieldRef<AddressSchema, String> =
    FieldRef::new(AddressFilterField::Street);
pub const ADDRESS_POSTAL_CODE: FieldRef<AddressSchema, String> =
    FieldRef::new(AddressFilterField::PostalCode);
pub const ADDRESS_CREATED_AT: FieldRef<AddressSchema, OffsetDateTime> =
    FieldRef::new(AddressFilterField::CreatedAt);
