export enum BlockchainFunction {
	CreateEvent = 'EVENT.CREATE',
	GetEvent = 'EVENT.GET',
	GetTicketConfig = 'EVENT.GET_TICKET_CONFIG',
	CreateTicketConfig = 'EVENT.ADD_TICKET_CONFIG',
	IssueTicket = 'TICKET.ISSUE',
	GetTicket = 'TICKET.GET',
	TransferTicket = 'TICKET.TRANSFER',
	InvalidateTicket = 'TICKET.INVALIDATE',
	ActivateTicket = 'TICKET.ACTIVATE',
	ApproveKyc = 'TICKET.APPROVE_KYC',
	MarkForSale = 'TICKET.MARK_FOR_SALE',
}

/**
 * Represents a function call on Hyperledger Fabric.
 * In our system, all functions take 1 parameter which is a JSON stringified object.
 * This is internally wrapped in an array.
 *
 * @param fcn The name of the function invoked
 * @param args The parameter for the function
 */
export interface BlockchainFunctionParams<T = any> {
	fcn: BlockchainFunction | string
	args: T
}

/**
 * Represents an entire transaction proposal. This needs to be signed later.
 *
 * @param certificate the certificate of the invoker
 */
export interface TransactionProposalPayload extends BlockchainFunctionParams {
	certificate: string
}

export interface Signature {
	signature: string
}

export interface Digest {
	digest: string
}

export interface SignedDigest extends Signature, Digest {}

export interface TxStatus {
	info: string
	status: string
}

export interface KeyPair {
	certificate: string
	privateKey: string
}

export interface TicketOffer {
	tickets: SingleTicketOffer[]
	seller_id: string
}

export interface TicketBcId {
	seq_num: number
	ticket_config: TicketConfigId
}

interface TicketConfigId {
	id: number
	event: EventId
}

interface EventId {
	id: number
}

export interface SingleTicketOffer extends TicketBcId {
	locked_until: string
	price: number
	type: OfferType
	buyer_id?: string
}

export interface InvalidateTicket extends TicketBcId {
	validation_time: string
}

export enum OfferType {
	Direct = 'DIRECT',
	Market = 'MARKET',
	Auction = 'AUCTION',
}

export interface TickedIds {
	eventId: number
	ticketConfigId: number
	sequenceNumber: number
}

export interface TransferTicketsRequest {
	data: TransferTicketEntity[]
}

export interface TransferTicketEntity {
	seqNum: number
	ticketConfig: {
		id: number
		event: {
			id: number
		}
	}
	newOwnerId: string
}
