pragma solidity ^0.4.16;
/*

    GOeureka SimpleAudit Smart Contract

    This contract stores a client and supplier reference between customers and
    hotels on the blockchain for audit log purposes

    bytes32 goeureka_audit_ref
    - a blockchain reference ID generated by goeureka

    string reference
    - a hash of two reference code from supplier and goeureka

*/
contract SimpleAudit {

    event AuditLog(bytes32 goeureka_audit_ref, string reference); // event

    struct Audit {
        string reference;        // a hash of two reference code from supplier and goeureka
        bool exist;              // checks if the reference exists
    }

    address creator;
    mapping(bytes32 => Audit) public records;

    constructor() public {
        creator = msg.sender;
    }

    modifier onlyOwner {
        require(
            msg.sender == creator, "Only owner can call this function."
        );
        _;
    }

    modifier noEdit(bytes32 goeureka_audit_ref) {

        require(
            records[goeureka_audit_ref].exist == false,
            "Already set, audit log cannot be modified"
        );
        _;
    }

    function set(bytes32 goeureka_audit_ref, string reference)
        onlyOwner
        noEdit(goeureka_audit_ref)
        public {
            records[goeureka_audit_ref].reference = reference;
            records[goeureka_audit_ref].exist = true;
            emit AuditLog(goeureka_audit_ref, reference);
    }

    function get(bytes32 goeureka_audit_ref) public constant returns (string) {
        return records[goeureka_audit_ref].reference;
    }

}