content: {-# LANGUAGE DataKinds #-}
  {-# LANGUAGE DeriveAnyClass #-}
  {-# LANGUAGE DeriveGeneric #-}
  {-# LANGUAGE DerivingStrategies #-}
  {-# LANGUAGE FlexibleContexts #-}
  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE GADTs #-}
  {-# LANGUAGE ImportQualifiedPost #-}
  {-# LANGUAGE LambdaCase #-}
  {-# LANGUAGE MultiParamTypeClasses #-}
  {-# LANGUAGE OverloadedStrings #-}
  {-# LANGUAGE RecordWildCards #-}
  {-# LANGUAGE ScopedTypeVariables #-}
  {-# LANGUAGE StandaloneDeriving #-}
  {-# LANGUAGE TypeApplications #-}
  {-# LANGUAGE UndecidableInstances #-}
  {-# LANGUAGE ViewPatterns #-}
  
  module Main where
  
  import AuctionMintingPolicy
  import Data.ByteString.Short qualified as Short
  import Data.Set qualified as Set
  import PlutusLedgerApi.Common (serialiseCompiledCode)
  import PlutusTx.Blueprint
  import System.Environment (getArgs)
  
  myContractBlueprint :: ContractBlueprint
  myContractBlueprint =
    MkContractBlueprint
      { contractId = Just "auction-minting-policy"
      , contractPreamble = myPreamble
      , contractValidators = Set.singleton myValidator
      , contractDefinitions = deriveDefinitions @[AuctionMintingParams, ()]
      }
  
  myPreamble :: Preamble
  myPreamble =
    MkPreamble
      { preambleTitle = "Auction Minting Policy"
      , preambleDescription = Just "A simple minting policy"
      , preambleVersion = "1.0.0"
      , preamblePlutusVersion = PlutusV2
      , preambleLicense = Just "MIT"
      }
  
  myValidator :: ValidatorBlueprint referencedTypes
  myValidator =
    MkValidatorBlueprint
      { validatorTitle = "Auction Minting Validator"
      , validatorDescription = Just "A simple minting validator"
      , validatorParameters =
          [ MkParameterBlueprint
              { parameterTitle = Just "Minting Validator Parameters"
              , parameterDescription = Just "Compile-time validator parameters"
              , parameterPurpose = Set.singleton Mint
              , parameterSchema = definitionRef @AuctionMintingParams
              }
          ]
      , validatorRedeemer =
          MkArgumentBlueprint
            { argumentTitle = Just "Redeemer for the minting policy"
            , argumentDescription = Just "The minting policy does not use a redeemer, hence ()"
            , argumentPurpose = Set.fromList [Mint]
            , argumentSchema = definitionRef @()
            }
      , validatorDatum = Nothing
      , validatorCompiled = do 
          let script = auctionMintingPolicyScript (error "Replace with seller public key hash")
          let code = Short.fromShort (serialiseCompiledCode script) 
          Just (compiledValidator PlutusV2 code)
      }
  
  writeBlueprintToFile :: FilePath -> IO ()
  writeBlueprintToFile path = writeBlueprint path myContractBlueprint
  
  main :: IO ()
  main =
    getArgs >>= \case
      [arg] -> writeBlueprintToFile arg
      args -> fail $ "Expects one argument, got " <> show (length args)
  