import { Optional } from "@nestjs/common";
import { ApiProperty } from "@nestjs/swagger";
import { IsString, IsOptional, IsNotEmpty, IsMongoId, IsNumber, Min } from "class-validator";
import { Transform } from 'class-transformer';
import { Types } from 'mongoose'
export enum agent_type {
    DRIVER_AGENT = 'DRIVER_AGENT',
    FARMER_AGENT = 'FARMER_AGENT'
}

export enum account_type {
    ACTIVATED = 'ACTIVATED',
    DEACTIVATED = 'DEACTIVATED',
    BLOCKED = 'BLOCKED'
}

export class signup_agent {

    // @IsOptional()
    @ApiProperty({ required: false, enum: Object.values(agent_type), default: agent_type.DRIVER_AGENT })
    @IsString()
    type: string;

    @ApiProperty()
    @IsString()
    email: string

    @ApiProperty()
    @Optional()
    @IsString()
    name: string

    @ApiProperty()
    @IsString()
    password: string

    @ApiProperty()
    @IsString()
    country_code: string

    @ApiProperty({ required: false })
    @IsOptional()
    phone_no: number

    @ApiProperty()
    @IsOptional()
    @IsString()
    driving_license: string

    @ApiProperty()
    @IsOptional()
    @IsString()
    national_id: string

    @ApiProperty()
    @IsOptional()
    @IsString()
    vehicle_license: string

}


export class list_agent {

    @ApiProperty({ type: String, description: "search by name", required: false })
    @IsOptional()
    @IsString()
    search?: string;

    @ApiProperty({ type: "number", default: 0, required: false })
    @IsOptional()
    pagination: number;

    @ApiProperty({ type: "number", default: 10, required: false })
    @IsOptional()
    limit?: number;

    @ApiProperty({ enum: account_type, default: "ACTIVATED", required: false })
    @IsOptional()
    @IsString()
    filter?: account_type;

}

export class farmer_monthly_income {

    @ApiProperty({ type: String })
    @IsNotEmpty()
    @IsMongoId()
    // @Transform(({ value }) => (Types.ObjectId.isValid(value) ? new Types.ObjectId(value) : value))
    farmer_id: string;

    @ApiProperty({ type: "number" })
    @IsNotEmpty()
    @IsNumber()
    @Min(1, { message: 'Monthly income must be greater than zero' })
    monthly_income: number;

}

export class Pagination {

    @ApiProperty({ type: "number", default: 0, required: false })
    @IsOptional()
    pagination: number;

    @ApiProperty({ type: "number", default: 10, required: false })
    @IsOptional()
    limit?: number;
}

export class Cancel_Reason {

    @ApiProperty({ type: "string", default: null, required: true })
    @IsString()
    cancel_reason: string;
}

export class Status {
    @ApiProperty({ type: "string", default: "DELIVERED", required: true, enum: ["DELIVERED", "CANCELLED"] })
    @IsString()
    status: string;

    @ApiProperty({ type: "string", default: null, required: true })
    @IsString()
    @IsOptional()
    cancel_reason: string;
}

export class login_as_agent {

    @ApiProperty({ type: 'string', required: false, default: "" })
    @IsString()
    _id: string;

}


