import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
import { Track } from '../entities/Track';

/**
 * This classed is used to create a new Track entity from a json body (post request).
 */
export class CreateTrack {
    /**
     * The new track's name.
     */
    @IsString()
    @IsNotEmpty()
    name: string;

    /**
     * The new track's distance in meters (must be greater than 0).
     */
    @IsInt()
    @IsPositive()
    distance: number;

    /**
     * Creates a new Track entity from this.
     */
    public toTrack(): Track {
        let newTrack: Track = new Track();

        newTrack.name = this.name;
        newTrack.distance = this.distance;

        return newTrack;
    }
}