<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class WaveCycle extends BaseModel
{
    use HasFactory;
    protected $fillable=['user_id','wave_cycle'];

    public function insertUserWaveCycle($inputData)
    {
        $result = [];
        $cycleObj = self::where('user_id',$inputData['user_id'])->first();
        if(!empty($cycleObj))
        {
            $inputData['wave_cycle'] = $cycleObj['wave_cycle'] + 1;
            $result['data'] = $cycleObj->update($inputData);
        }
        else{
            $inputData['wave_cycle'] = 1;
            $result['data'] = self::create($inputData);
        }

        $result['message'] = 'save successfully';
        $result['status'] = true;
        return $result;

    }
}
