// Generated by Qleany v1.7.0 from entity_dtos.tera

use common::entities::Field;
pub use common::entities::FieldRelationshipType;
pub use common::entities::FieldType;
use common::types::EntityId;
use serde::{Deserialize, Serialize};
use std::convert::From;

#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct FieldDto {
    pub id: EntityId,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
    pub name: String,
    pub field_type: FieldType,
    pub entity: Option<EntityId>,
    pub relationship: FieldRelationshipType,
    pub optional: bool,
    pub is_list: bool,
    pub strong: bool,
    pub list_model: bool,
    pub list_model_displayed_field: Option<String>,
    pub enum_name: Option<String>,
    pub enum_values: Vec<String>,
}

impl From<FieldDto> for Field {
    fn from(dto: FieldDto) -> Self {
        Field {
            id: dto.id,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name,
            field_type: dto.field_type,
            entity: dto.entity,
            relationship: dto.relationship,
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field,
            enum_name: dto.enum_name,
            enum_values: dto.enum_values,
        }
    }
}

impl From<&FieldDto> for Field {
    fn from(dto: &FieldDto) -> Self {
        Field {
            id: dto.id,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name.clone(),
            field_type: dto.field_type.clone(),
            entity: dto.entity,
            relationship: dto.relationship.clone(),
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field.clone(),
            enum_name: dto.enum_name.clone(),
            enum_values: dto.enum_values.clone(),
        }
    }
}

impl From<Field> for FieldDto {
    fn from(entity: Field) -> Self {
        FieldDto {
            id: entity.id,
            created_at: entity.created_at,
            updated_at: entity.updated_at,
            name: entity.name,
            field_type: entity.field_type,
            entity: entity.entity,
            relationship: entity.relationship,
            optional: entity.optional,
            is_list: entity.is_list,
            strong: entity.strong,
            list_model: entity.list_model,
            list_model_displayed_field: entity.list_model_displayed_field,
            enum_name: entity.enum_name,
            enum_values: entity.enum_values,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct CreateFieldDto {
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
    pub name: String,
    pub field_type: FieldType,
    pub entity: Option<EntityId>,
    pub relationship: FieldRelationshipType,
    pub optional: bool,
    pub is_list: bool,
    pub strong: bool,
    pub list_model: bool,
    pub list_model_displayed_field: Option<String>,
    pub enum_name: Option<String>,
    pub enum_values: Vec<String>,
}

impl From<CreateFieldDto> for Field {
    fn from(dto: CreateFieldDto) -> Self {
        Field {
            id: 0,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name,
            field_type: dto.field_type,
            entity: dto.entity,
            relationship: dto.relationship,
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field,
            enum_name: dto.enum_name,
            enum_values: dto.enum_values,
        }
    }
}

impl From<&CreateFieldDto> for Field {
    fn from(dto: &CreateFieldDto) -> Self {
        Field {
            id: 0,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name.clone(),
            field_type: dto.field_type.clone(),
            entity: dto.entity,
            relationship: dto.relationship.clone(),
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field.clone(),
            enum_name: dto.enum_name.clone(),
            enum_values: dto.enum_values.clone(),
        }
    }
}

impl From<Field> for CreateFieldDto {
    fn from(entity: Field) -> Self {
        CreateFieldDto {
            created_at: entity.created_at,
            updated_at: entity.updated_at,
            name: entity.name,
            field_type: entity.field_type,
            entity: entity.entity,
            relationship: entity.relationship,
            optional: entity.optional,
            is_list: entity.is_list,
            strong: entity.strong,
            list_model: entity.list_model,
            list_model_displayed_field: entity.list_model_displayed_field,
            enum_name: entity.enum_name,
            enum_values: entity.enum_values,
        }
    }
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct UpdateFieldDto {
    pub id: EntityId,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
    pub name: String,
    pub field_type: FieldType,
    pub relationship: FieldRelationshipType,
    pub optional: bool,
    pub is_list: bool,
    pub strong: bool,
    pub list_model: bool,
    pub list_model_displayed_field: Option<String>,
    pub enum_name: Option<String>,
    pub enum_values: Vec<String>,
}

impl From<UpdateFieldDto> for Field {
    fn from(dto: UpdateFieldDto) -> Self {
        Field {
            id: dto.id,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name,
            field_type: dto.field_type,
            relationship: dto.relationship,
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field,
            enum_name: dto.enum_name,
            enum_values: dto.enum_values,
            entity: Default::default(),
        }
    }
}

impl From<&UpdateFieldDto> for Field {
    fn from(dto: &UpdateFieldDto) -> Self {
        Field {
            id: dto.id,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name.clone(),
            field_type: dto.field_type.clone(),
            relationship: dto.relationship.clone(),
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field.clone(),
            enum_name: dto.enum_name.clone(),
            enum_values: dto.enum_values.clone(),
            entity: Default::default(),
        }
    }
}

impl From<Field> for UpdateFieldDto {
    fn from(entity: Field) -> Self {
        UpdateFieldDto {
            id: entity.id,
            created_at: entity.created_at,
            updated_at: entity.updated_at,
            name: entity.name,
            field_type: entity.field_type,
            relationship: entity.relationship,
            optional: entity.optional,
            is_list: entity.is_list,
            strong: entity.strong,
            list_model: entity.list_model,
            list_model_displayed_field: entity.list_model_displayed_field,
            enum_name: entity.enum_name,
            enum_values: entity.enum_values,
        }
    }
}

impl From<FieldDto> for UpdateFieldDto {
    fn from(dto: FieldDto) -> Self {
        UpdateFieldDto {
            id: dto.id,
            created_at: dto.created_at,
            updated_at: dto.updated_at,
            name: dto.name,
            field_type: dto.field_type,
            relationship: dto.relationship,
            optional: dto.optional,
            is_list: dto.is_list,
            strong: dto.strong,
            list_model: dto.list_model,
            list_model_displayed_field: dto.list_model_displayed_field,
            enum_name: dto.enum_name,
            enum_values: dto.enum_values,
        }
    }
}
pub use common::direct_access::field::FieldRelationshipField;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FieldRelationshipDto {
    pub id: EntityId,
    pub field: FieldRelationshipField,
    pub right_ids: Vec<EntityId>,
}
