<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class SellTarget extends Model
{
    use HasFactory;

    protected $hidden = ['user_id'];

    public static function saveBasicInfo($sellTarget, $request)
    {
        $sellTarget->target_type = $request->target_type;
        $sellTarget->target_amount = $request->target_amount;
        $sellTarget->save();

        return $sellTarget;
    }

    public static function newSellTarget($request)
    {
        $sellTarget = new self;
        $sellTarget->user_id = Auth::id();
        $sellTarget->staff_id = $request->staff_id;

        return self::saveBasicInfo($sellTarget, $request);
    }

    public static function updateSellTarget($request)
    {
        return self::saveBasicInfo(self::query()->where('staff_id', '=', $request->staff_id)->first(), $request);
    }
}
