syntax = "proto3";

import "gogo/protobuf/gogoproto/gogo.proto";
import "protobuf/types/struct.proto";

package mesg.types;
option go_package = "github.com/mesg-foundation/engine/execution";

option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = true;

// Status represents the status of a single execution.
// Note that a valid execution must have only one status
// flag at time.
enum Status {
  // Unknown status represents any status unknown to execution.
  Unknown = 0;

  // Created is an initial status after execution creation.
  Created = 1;

  // InProgress informs that processing of execution has been started.
  InProgress = 2;

  // Completed is a success status after execution was processed.
  Completed = 3;

  // Failed is an error status after execution was processed.
  Failed = 4;
}

// Execution represents a single execution run in engine.
message Execution {
  // Hash is a unique hash to identify execution.
  bytes hash = 1 [
    (gogoproto.moretags) = 'hash:"-"',
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];

  // parentHash is the unique hash of parent execution.
  // if execution is triggered by another one,
  // dependency execution considered as the parent.
  bytes parentHash = 2 [
    (gogoproto.moretags) = 'hash:"name:2"',
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];

  // eventHash is unique event hash.
  bytes eventHash = 3 [
    (gogoproto.moretags) = 'hash:"name:3"',
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];

  // Status is the current status of execution.
  Status status = 4 [
    (gogoproto.moretags) = 'hash:"-"'
  ];

  // instanceHash is hash of the instance that can proceed an execution
  bytes instanceHash = 5 [
    (gogoproto.moretags) = 'hash:"name:5"',
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];

  // taskKey is the key of the task of this execution.
  string taskKey = 6 [
    (gogoproto.moretags) = 'hash:"name:6"'
  ];

  // inputs data of the execution.
  mesg.protobuf.Struct inputs = 7 [
    (gogoproto.moretags) = 'hash:"name:7"'
  ];

  // outputs are the returned data of successful execution.
  mesg.protobuf.Struct outputs = 8 [
    (gogoproto.moretags) = 'hash:"-"'
  ];

  // error message of a failed execution.
  string error = 9 [
    (gogoproto.moretags) = 'hash:"-"'
  ];

  // tags are optionally associated with execution by the user.
  repeated string tags = 10 [
    (gogoproto.moretags) = 'hash:"name:10"'
  ];

  // processHash is the unique hash of the process associated to this execution.
  bytes processHash = 11 [
    (gogoproto.moretags) = 'hash:"name:11"',
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];

  // step of the process.
  string stepID = 12 [
    (gogoproto.moretags) = 'hash:"name:12"'
  ];
}
