import { IsInt, IsObject, IsOptional, IsPositive, IsString } from "class-validator";
import { Address } from '../entities/Address';
import { Participant } from '../entities/Participant';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';

/**
 * Defines the participant response.
*/
export abstract class ResponseParticipant implements IResponse {
    /**
    * The responseType.
    * This contains the type of class/entity this response contains.
    */
    responseType: ResponseObjectType = ResponseObjectType.PARTICIPANT;

    /**
     * The participant's id.
     */
    @IsInt()
    id: number;

    /**
     * The participant's first name.
     */
    @IsString()
    firstname: string;

    /**
     * The participant's middle name.
     */
    @IsString()
    middlename?: string;

    /**
     * The participant's last name.
     */
    @IsString()
    lastname: string;

    /**
     * The participant's phone number.
     */
    @IsString()
    phone?: string;

    /**
     * The participant's e-mail address.
     */
    @IsString()
    email?: string;

    /**
     * how the participant got into the system
     */
    @IsString()
    created_via?: string;

    /**
     * The participant's address.
     */
    @IsOptional()
    @IsObject()
    address?: Address;

    @IsInt()
    @IsPositive()
    created_at: number;

    @IsInt()
    @IsPositive()
    updated_at: number;

    /**
     * Creates a ResponseParticipant object from a participant.
     * @param participant The participant the response shall be build for.
     */
    public constructor(participant: Participant) {
        this.id = participant.id;
        this.firstname = participant.firstname;
        this.created_via = participant.created_via;
        this.middlename = participant.middlename;
        this.lastname = participant.lastname;
        this.phone = participant.phone;
        this.email = participant.email;
        this.address = participant.address;
        this.created_at = participant.created_at;
        this.updated_at = participant.updated_at;
    }
}
