<?php

namespace Bixo\Niche\Workflow;

use Exception;
use Litepie\Workflow\Exceptions\WorkflowActionNotPerformedException;

use Bixo\Niche\Models\Niche;

class NicheAction
{
    /**
     * Perform the complete action.
     *
     * @param Niche $niche
     *
     * @return Niche
     */
    public function complete(Niche $niche)
    {
        try {
            $niche->status = 'complete';
            return $niche->save();
        } catch (Exception $e) {
            throw new WorkflowActionNotPerformedException();
        }
    }

    /**
     * Perform the verify action.
     *
     * @param Niche $niche
     *
     * @return Niche
     */public function verify(Niche $niche)
    {
        try {
            $niche->status = 'verify';
            return $niche->save();
        } catch (Exception $e) {
            throw new WorkflowActionNotPerformedException();
        }
    }

    /**
     * Perform the approve action.
     *
     * @param Niche $niche
     *
     * @return Niche
     */public function approve(Niche $niche)
    {
        try {
            $niche->status = 'approve';
            return $niche->save();
        } catch (Exception $e) {
            throw new WorkflowActionNotPerformedException();
        }
    }

    /**
     * Perform the publish action.
     *
     * @param Niche $niche
     *
     * @return Niche
     */public function publish(Niche $niche)
    {
        try {
            $niche->status = 'publish';
            return $niche->save();
        } catch (Exception $e) {
            throw new WorkflowActionNotPerformedException();
        }
    }

    /**
     * Perform the archive action.
     *
     * @param Niche $niche
     *
     * @return Niche
     */
    public function archive(Niche $niche)
    {
        try {
            $niche->status = 'archive';
            return $niche->save();
        } catch (Exception $e) {
            throw new WorkflowActionNotPerformedException();
        }
    }

    /**
     * Perform the unpublish action.
     *
     * @param Niche $niche
     *
     * @return Niche
     */
    public function unpublish(Niche $niche)
    {
        try {
            $niche->status = 'unpublish';
            return $niche->save();
        } catch (Exception $e) {
            throw new WorkflowActionNotPerformedException();
        }
    }
}