// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract EUMToken {
    string public name = "EUM Token";
    string public symbol = "EUM";
    uint8 public decimals = 18;
    uint256 public totalSupply;

    uint256 public tokenPriceInCents = 100; // 1 dollar (100 cents)
    uint256 public transactionFeePercentage = 1; // 1% transaction fee

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor(uint256 initialSupply) {
        totalSupply = initialSupply * 10**uint256(decimals);
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address to, uint256 value) public returns (bool) {
        require(to != address(0), "Invalid address");
        require(value <= balanceOf[msg.sender], "Insufficient balance");

        uint256 transactionFee = (value * transactionFeePercentage) / 100;
        uint256 transferAmount = value - transactionFee;

        balanceOf[msg.sender] -= value;
        balanceOf[to] += transferAmount;

        emit Transfer(msg.sender, to, transferAmount);

        // Collect transaction fee
        if (transactionFee > 0) {
            balanceOf[address(this)] += transactionFee;
            emit Transfer(msg.sender, address(this), transactionFee);
        }

        return true;
    }

    function approve(address spender, uint256 value) public returns (bool) {
        allowance[msg.sender][spender] = value;

        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) public returns (bool) {
        require(to != address(0), "Invalid address");
        require(value <= balanceOf[from], "Insufficient balance");
        require(value <= allowance[from][msg.sender], "Allowance exceeded");

        uint256 transactionFee = (value * transactionFeePercentage) / 100;
        uint256 transferAmount = value - transactionFee;

        balanceOf[from] -= value;
        balanceOf[to] += transferAmount;
        allowance[from][msg.sender] -= value;

        emit Transfer(from, to, transferAmount);

        // Collect transaction fee
        if (transactionFee > 0) {
            balanceOf[address(this)] += transactionFee;
            emit Transfer(from, address(this), transactionFee);
        }

        return true;
    }

    function setTokenPriceInCents(uint256 priceInCents) external {
        tokenPriceInCents = priceInCents;
    }

    function setTransactionFeePercentage(uint256 feePercentage) external {
        require(feePercentage <= 100, "Fee percentage must be <= 100");
        transactionFeePercentage = feePercentage;
    }
}