// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IGhostAuthority} from "../interfaces/IGhostAuthority.sol";

abstract contract GhostAccessControlled {
    error Unauthorized();

    event AuthorityUpdated(address authority);

    IGhostAuthority public authority;

    constructor(IGhostAuthority _authority) {
        authority = _authority;
        emit AuthorityUpdated(address(_authority));
    }

    modifier onlyGovernor {
    	_onlyGovernor();
    	_;
    }

    modifier onlyGuardian {
    	_onlyGuardian();
    	_;
    }

    modifier onlyPolicy {
    	_onlyPolicy();
    	_;
    }

    modifier onlyVault {
    	_onlyVault();
    	_;
    }

    function setAuthority(address newAuthority) external {
        _onlyGovernor();
        authority = IGhostAuthority(newAuthority);
        emit AuthorityUpdated(newAuthority);
    }

    function _onlyGovernor() internal view {
        if (msg.sender != authority.governor()) revert Unauthorized();
    }

    function _onlyGuardian() internal view {
        if (msg.sender != authority.guardian()) revert Unauthorized();
    }

    function _onlyPolicy() internal view {
        if (msg.sender != authority.policy()) revert Unauthorized();
    }

    function _onlyVault() internal view {
        if (msg.sender != authority.vault()) revert Unauthorized();
    }
}
