<?php

namespace App\Services\Part;

use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\DISKEntity;
use App\Helpers\Part\DISKHelper;
use App\Models\Part\DISKModel;


class DISKService extends PartService
{
    public function __construct()
    {
        parent::__construct(new DISKModel(), new DISKHelper());
        $this->addClassName('DISK');
    }
    public function getFormFields(): array
    {
        return [
            "title",
            "price",
            "stock",
            "format",
            "status",
        ];
    }
    public function getFormFilters(): array
    {
        return [
            'status',
        ];
    }
    public function getIndexFields(): array
    {
        return [
            "title",
            "price",
            "used",
            "stock",
            "format",
            "status",
        ];
    }
    public function getBatchjobFields(): array
    {
        return ['status'];
    }
    //기본 기능부분
    //FieldForm관련용
    //OrderBy 처리
    public function setOrderBy(mixed $field = null, mixed $value = null): void
    {
        $this->getModel()->orderBy('title ASC');
        parent::setOrderBy($field, $value);
    }

    //서버파트관련 작업
    public function detachFromServerPart(ServerPartEntity $serverPartEntity): DiskEntity
    {
        $entity = parent::detachFromServerPart($serverPartEntity);
        return $this->getModel()->modify($entity, ['format' => $entity->getFormat() + $serverPartEntity->getCnt()]);
    }
}
