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

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

use toolkit_odata::filter::FilterField as _;

/// User filterable fields schema.
///
/// This struct defines which fields can be used in `OData` $filter queries
/// for user resources. The field names match the wire format.
#[derive(ODataFilterable)]
pub struct UserQuery {
    #[odata(filter(kind = "Uuid"))]
    pub id: Uuid,

    #[odata(filter(kind = "String"))]
    pub email: 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 users.
pub use UserQueryFilterField as UserFilterField;

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

impl Schema for UserSchema {
    type Field = UserFilterField;

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

pub const USER_ID: FieldRef<UserSchema, Uuid> = FieldRef::new(UserFilterField::Id);
pub const USER_EMAIL: FieldRef<UserSchema, String> = FieldRef::new(UserFilterField::Email);
pub const USER_CREATED_AT: FieldRef<UserSchema, OffsetDateTime> =
    FieldRef::new(UserFilterField::CreatedAt);
