<?php

namespace Litecms\Country\Policies;

use Litepie\User\Contracts\UserPolicy;
use Litecms\Country\Models\Country;

class CountryPolicy
{

    /**
     * Determine if the given user can view the country.
     *
     * @param UserPolicy $user
     * @param Country $country
     *
     * @return bool
     */
    public function view(UserPolicy $user, Country $country)
    {
        if ($user->canDo('country.country.view') && $user->isAdmin()) {
            return true;
        }

        return $country->user_id == user_id() && $country->user_type == user_type();
    }

    /**
     * Determine if the given user can create a country.
     *
     * @param UserPolicy $user
     * @param Country $country
     *
     * @return bool
     */
    public function create(UserPolicy $user)
    {
        return  $user->canDo('country.country.create');
    }

    /**
     * Determine if the given user can update the given country.
     *
     * @param UserPolicy $user
     * @param Country $country
     *
     * @return bool
     */
    public function update(UserPolicy $user, Country $country)
    {
        if ($user->canDo('country.country.edit') && $user->isAdmin()) {
            return true;
        }

        return $country->user_id == user_id() && $country->user_type == user_type();
    }

    /**
     * Determine if the given user can delete the given country.
     *
     * @param UserPolicy $user
     * @param Country $country
     *
     * @return bool
     */
    public function destroy(UserPolicy $user, Country $country)
    {
        return $country->user_id == user_id() && $country->user_type == user_type();
    }

    /**
     * Determine if the given user can verify the given country.
     *
     * @param UserPolicy $user
     * @param Country $country
     *
     * @return bool
     */
    public function verify(UserPolicy $user, Country $country)
    {
        if ($user->canDo('country.country.verify')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the given user can approve the given country.
     *
     * @param UserPolicy $user
     * @param Country $country
     *
     * @return bool
     */
    public function approve(UserPolicy $user, Country $country)
    {
        if ($user->canDo('country.country.approve')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the user can perform a given action ve.
     *
     * @param [type] $user    [description]
     * @param [type] $ability [description]
     *
     * @return [type] [description]
     */
    public function before($user, $ability)
    {
        if ($user->isSuperuser()) {
            return true;
        }
    }
}