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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";

contract EasyBRLStable is ERC20, ERC20Burnable, AccessControl, Pausable {
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant COMPLIANCE_ROLE = keccak256("COMPLIANCE_ROLE");

    mapping(address => bool) private _blacklist;

    event BlacklistUpdated(address indexed account, bool isBlacklisted);

    constructor(address admin, string memory name_, string memory symbol_) ERC20(name_, symbol_) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
        _grantRole(PAUSER_ROLE, admin);
        _grantRole(MINTER_ROLE, admin);
        _grantRole(COMPLIANCE_ROLE, admin);
    }

    function decimals() public pure override returns (uint8) {
        return 6;
    }

    function pause() external onlyRole(PAUSER_ROLE) {
        _pause();
    }

    function unpause() external onlyRole(PAUSER_ROLE) {
        _unpause();
    }

    function setBlacklist(address account, bool status) external onlyRole(COMPLIANCE_ROLE) {
        _blacklist[account] = status;
        emit BlacklistUpdated(account, status);
    }

    function isBlacklisted(address account) external view returns (bool) {
        return _blacklist[account];
    }

    function mint(address to, uint256 amount) external onlyRole(DEFAULT_ADMIN_ROLE) {
        _mint(to, amount);
    }

    function burn(uint256 value) public override onlyRole(DEFAULT_ADMIN_ROLE) {
        super.burn(value);
    }

    function burnFrom(address account, uint256 value) public override onlyRole(DEFAULT_ADMIN_ROLE) {
        super.burnFrom(account, value);
    }

    function _update(address from, address to, uint256 value) internal override whenNotPaused {
        if (from != address(0)) {
            require(!_blacklist[from], "Blacklisted");
        }
        if (to != address(0)) {
            require(!_blacklist[to], "Blacklisted");
        }
        require(!_blacklist[_msgSender()], "Blacklisted");
        super._update(from, to, value);
    }

    function grantComplianceRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
        _grantRole(COMPLIANCE_ROLE, account);
    }
}
