contract GiftToken is Context, IERC20 {
    
    string private constant _name = "GiftCoin";
    string private constant _description = "It's the idea that counts :) Enjoy your gift!";
    string private constant _symbol = "GIFT";
    uint8 private constant _decimals = 18;

    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) _allowances;

    uint256 _totalSupply;
    address _owner;

    using SafeMath for uint256;

    constructor(address owner) {
        require(owner != address(0), "Cannot give token ownership to zero address");
        _totalSupply = 1000000000000000000000;
        _balances[owner] = _balances[owner].add(1000000000000000000000);
        _owner = owner;
    }

    // === MODIFIERS ===
    // Modifier that checks if the sender is the owner - executed at same level as
    // the function calling it i.e. it gets injected where it gets called from
    modifier onlyOwner() {
        require(_msgSender() == _owner, "Caller is not the owner");
        _; // This continues the function
    }

    // === GETTERS ===
    function totalSupply() public override view returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) public override view returns (uint256) {
        return _balances[account];
    }

    function name() public pure returns (string memory) {
        return _name;
    }

    function symbol() public pure returns (string memory) {
        return _symbol;
    }
    
    function openGift() public pure returns (string memory) {
        return _description;
    }

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

    // === FUNCTIONS ===
    function transfer(address recipient, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function allowance(address owner, address spender)
        public
        virtual
        override
        view
        returns (uint256)
    {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(
            sender,
            _msgSender(),
            _allowances[sender][_msgSender()].sub(
                amount,
                "ERC20: transfer amount exceeds allowance"
            )
        );
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue)
        public
        virtual
        returns (bool)
    {
        _approve(
            _msgSender(),
            spender,
            _allowances[_msgSender()][spender].add(addedValue)
        );
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue)
        public
        virtual
        returns (bool)
    {
        _approve(
            _msgSender(),
            spender,
            _allowances[_msgSender()][spender].sub(
                subtractedValue,
                "ERC20: decreased allowance below zero"
            )
        );
        return true;
    }

    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(
            amount,
            "ERC20: transfer amount exceeds balance"
        );
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    function getOwner() public view returns (address) {
        return _owner;
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hands over contract to an address - USE WITH CAUTION
     * IF ADDRESS IS A CONTRACT, YOU MIGHT NEVER GET IT BACK.
     */
    function handOverContract(address toAccount) public onlyOwner {
        _owner = toAccount;
    }
}
function transfer(address recipient, uint256 amount)
    public
    virtual
    override
    returns (bool)
{
    _transfer(_msgSender(), recipient, amount);
    return true;
}

// === FUNCTIONS ===