<?php

namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;

class CourseSemesterFeesTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('course_semester_fees');
        $this->setDisplayField('id');
        $this->setPrimaryKey('id');

        $this->addBehavior('Timestamp', [
            'created' => 'created_at',
            'modified' => 'updated_at',
        ]);

        // Optional associations
        $this->belongsTo('Courses');
    }

    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmptyString('id', null, 'create');

        $validator
            ->integer('course_id')
            ->requirePresence('course_id', 'create')
            ->notEmptyString('course_id');

        $validator
            ->decimal('online_fee')
            ->notEmptyString('online_fee');

        $validator
            ->decimal('discount')
            ->allowEmptyString('discount');

        $validator
            ->decimal('monthly_installment_amount')
            ->allowEmptyString('monthly_installment_amount');

        $validator
            ->decimal('upfront_deposit')
            ->allowEmptyString('upfront_deposit');

        $validator
            ->decimal('blended_fee')
            ->allowEmptyString('blended_fee');

        $validator
            ->decimal('certificate_fee')
            ->allowEmptyString('certificate_fee');

        $validator
            ->integer('status')
            ->allowEmptyString('status');

        $validator
            ->integer('created_by')
            ->allowEmptyString('created_by');

        $validator
            ->integer('updated_by')
            ->allowEmptyString('updated_by');

        $validator
            ->dateTime('created_at')
            ->allowEmptyDateTime('created_at');

        $validator
            ->dateTime('updated_at')
            ->allowEmptyDateTime('updated_at');

        return $validator;
    }
}