<?php

/*
 * This file is part of the ActiveCollab project.
 *
 * (c) A51 doo <info@activecollab.com>. All rights reserved.
 */

abstract class BaseTimeRecords extends DataManager
{
    /**
     * Return name of this model.
     *
     * @param  bool   $underscore
     * @return string
     */
    public static function getModelName($underscore = false)
    {
        return $underscore ? 'time_records' : 'TimeRecords';
    }

    /**
     * Return name of the table where system will persist model instances.
     *
     * @return string
     */
    public static function getTableName()
    {
        return 'time_records';
    }

    /**
     * All table fields.
     *
     * @var array
     */
    private static $fields = ['id', 'parent_type', 'parent_id', 'invoice_type', 'invoice_item_id', 'job_type_id', 'record_date', 'value', 'user_id', 'user_name', 'user_email', 'summary', 'billable_status', 'created_on', 'created_by_id', 'created_by_name', 'created_by_email', 'updated_on', 'updated_by_id', 'updated_by_name', 'updated_by_email', 'is_trashed', 'original_is_trashed', 'trashed_on', 'trashed_by_id', 'source', 'internal_rate', 'job_type_hourly_rate'];

    /**
     * Return a list of model fields.
     *
     * @return array
     */
    public static function getFields()
    {
        return self::$fields;
    }

    /**
     * Return class name of a single instance.
     *
     * @return string
     */
    public static function getInstanceClassName()
    {
        return 'TimeRecord';
    }

    /**
     * Return whether instance class name should be loaded from a field, or based on table name.
     *
     * @return string
     */
    public static function getInstanceClassNameFrom()
    {
        return DataManager::CLASS_NAME_FROM_TABLE;
    }

    /**
     * Return name of the field from which we will read instance class.
     *
     * @return string
     */
    public static function getInstanceClassNameFromField()
    {
        return '';
    }

    /**
     * Return name of this model.
     *
     * @return string
     */
    public static function getDefaultOrderBy()
    {
        return 'record_date DESC, created_on DESC';
    }

    public static function create(
        array $attributes,
        bool $save = true,
        bool $announce = true
    ): TimeRecord
    {
        return parent::create($attributes, $save, $announce);
    }

    public static function &update(
        DataObject &$instance,
        array $attributes,
        bool $save = true
    ): TimeRecord
    {
        return parent::update($instance, $attributes, $save);
    }

    /**
     * @return TimeRecord|bool
     */
    public static function scrap(
        DataObject &$instance,
        bool $force_delete = false
    )
    {
        return parent::scrap($instance, $force_delete);
    }
}
