# Silicon Overdrive
# Support: helpdesk@overdrive.co.za
# Tel: 27 21 448 5759
# https://www.overdrive.co.za/
#
# This is an serverless framework yml
#
#
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/details
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/update
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/user/details
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/logs
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/transactions
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/register
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/registerpayment
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/deletepayment
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/evidence
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getallfines
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getfinesearch
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/streamevidence
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getoutstandingfines
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getcharges
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/queryinfringements
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/queryinfringer
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/payinfringement
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/updateregistration
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/postsettings
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getgraphs
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getsettings
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/getgraphsettings
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/postgraphsettings
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/postiveritransaction
  # POST - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/iveripayment
  # GET - https://h8vzvoqq9c.execute-api.eu-west-1.amazonaws.com/development/runcronjob
################################

service: ${self:custom.settings.${opt:stage, self:provider.stage, 'development'}.service} # NOTE: update this with your service name

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

custom:
  vpc: ${file(./${opt:stage, self:provider.stage, 'development'}VpcConfig.yml)}
  settings: ${file(./environmentConfig.yml)}

provider:
  name: aws
  runtime: dotnet6
#  profile: ${self:custom.settings.${opt:stage, self:provider.stage, 'development'}.profile}
  region: eu-west-1
  stage: ${self:custom.settings.${opt:stage, self:provider.stage, 'development'}.stage}
  apiGateway:
    minimumCompressionSize: 1024
  vpc:
    securityGroupIds: ${self:custom.vpc.securityGroupIds}
    subnetIds: ${self:custom.vpc.subnetIds}

package:
  individually: true
  artifact: bin/release/net6.0/pay-my-fines-lambda.zip


functions:
  isRecaptchaValid:
    handler: AwsDotnetCsharp::PMF.Recaptcha::IsRecaptchaValid
    events:
      - http:
          path: recaptcha
          method: post
          cors: true
    #provisionedConcurrency: 5
  getLoggedInUserDetails:
    handler: AwsDotnetCsharp::PMF.GetLoggedInUser::GetLoggedInUserDetails
    events:
      - http:
          path: details
          method: get
          cors: true
    #provisionedConcurrency: 5
  postUserDetails:
    handler: AwsDotnetCsharp::PMF.PostUserDetail::PostUserDetails
    events:
      - http:
          path: update
          method: post
          cors: true
    #provisionedConcurrency: 5
  getUserDetails:
    handler: AwsDotnetCsharp::PMF.UserDetails::GetUserDetails
    events:
      - http:
          path: user/details
          method: get
          cors: true
    #provisionedConcurrency: 5
  getAPILogs:
    handler: AwsDotnetCsharp::PMF.ApiLogs::GetAPILogs
    events:
      - http:
          path: logs
          method: get
          cors: true
    #provisionedConcurrency: 5
  getTransactions:
    handler: AwsDotnetCsharp::PMF.TransactionList::GetTransactions
    events:
      - http:
          path: transactions
          method: get
          cors: true
    #provisionedConcurrency: 5
  registerUser:
    handler: AwsDotnetCsharp::PMF.Registration::RegisterUser
    events:
      - http:
          path: register
          method: post
          cors: true
    #provisionedConcurrency: 5
  registerpayment:
    handler: AwsDotnetCsharp::PMF.IForcePayment::PostPayment
    events:
      - http:
          path: registerpayment
          method: post
          cors: true
    #provisionedConcurrency: 5
  # deletepayment:
  #   handler: AwsDotnetCsharp::AwsDotnetCsharp.Handler::DeletePayment
  #   events:
  #     - http:
  #         path: deletepayment
  #         method: post
  #         cors: true
    #provisionedConcurrency: 5
  getEvidence:
    handler: AwsDotnetCsharp::PMF.IForceEvidence::GetEvidence
    events:
      - http:
          path: evidence
          method: get
          cors: true
    timeout: 30
    #provisionedConcurrency: 5
  getAllFines:
    handler: AwsDotnetCsharp::PMF.AllFines::GetAllFines
    events:
      - http:
          path: getallfines
          method: get
          cors: true
    timeout: 45
    #provisionedConcurrency: 5
  getPaginatedFines:
    handler: AwsDotnetCsharp::PMF.AllFines::GetPaginatedFines
    events:
      - http:
          path: getpaginatedfines
          method: get
          cors: true
    timeout: 45
    #provisionedConcurrency: 5
  getQuickFines:
    handler: AwsDotnetCsharp::PMF.QuickFines::GetQuickFines
    events:
      - http:
          path: getfinesearch
          method: get
          cors: true
    timeout: 30
    #provisionedConcurrency: 5
  getStreamEvidence:
    handler: AwsDotnetCsharp::PMF.StreamEvidence::GetStreamEvidence
    events:
      - http:
          path: streamevidence
          method: get
          cors: true
    timeout: 30
    #provisionedConcurrency: 5
  getoutstandingfines:
    handler: AwsDotnetCsharp::PMF.IForceOutStandingFines::GetOutstandingFines
    events:
      - http:
          path: getoutstandingfines
          method: get
          cors: true
    timeout: 30
    #provisionedConcurrency: 5
  getcharges:
    handler: AwsDotnetCsharp::PMF.GetCharge::GetCharges
    events:
      - http:
          path: getcharges
          method: get
          cors: true
    timeout: 30
    #provisionedConcurrency: 5
  queryinfringements:
    handler: AwsDotnetCsharp::PMF.QueryInfringement::QueryExternalInfringement
    events:
      - http:
          path: queryinfringements
          method: get
          cors: true
    timeout: 30
    #provisionedConcurrency: 5
  queryinfringer:
    handler: AwsDotnetCsharp::PMF.QueryInfringer::QueryExternalInfringer
    events:
      - http:
          path: queryinfringer
          method: get
          cors: true
    timeout: 30     
    #provisionedConcurrency: 5
  payinfringement:
    handler: AwsDotnetCsharp::PMF.PayEnatis::PayExternalInfringement
    events:
      - http:
          path: payinfringement
          method: post
          cors: true
    timeout: 30  
    #provisionedConcurrency: 5
  generateCustomMessage:
    handler: AwsDotnetCsharp::PMF.CognitoMail::GenerateCustomEmail
    events:
      - cognitoUserPool:
          pool: ${self:custom.settings.${opt:stage, self:provider.stage, 'development'}.userPool}
          trigger: CustomMessage
          existing: true
    environment:
      USERPOOL: ${self:custom.settings.${opt:stage, self:provider.stage, 'development'}.userPool}
    #provisionedConcurrency: 5
 
  updateRegistration:
    handler: AwsDotnetCsharp::PMF.RegistrationUpdate::UpdateRegistration
    events:
      - http:
          path: updateregistration
          method: post
          cors: true
    #provisionedConcurrency: 5
  postsettings:
    handler: AwsDotnetCsharp::PMF.UpdateSettings::PostUpdateSettings
    events:
      - http:
          path: postsettings
          method: post
          cors: true
    #provisionedConcurrency: 5
  getFinanceReportData:
    handler: AwsDotnetCsharp::PMF.FinanceReportData::GetFinanceReportData
    events:
      - http:
          path: reports
          method: get
          cors: true
    #provisionedConcurrency: 5
  getgraphs:
    handler: AwsDotnetCsharp::PMF.GetGraph::GetGraphs
    events:
      - http:
          path: getgraphs
          method: get
          cors: true
    #provisionedConcurrency: 5
  getsettings:
    handler: AwsDotnetCsharp::PMF.SystemSettings::GetSettings
    events:
      - http:
          path: getsettings
          method: get
          cors: true
    #provisionedConcurrency: 5
  getgraphsettings:
    handler: AwsDotnetCsharp::PMF.GraphSettingsGet::GetGraphSettings
    events:
      - http:
          path: getgraphsettings
          method: get
          cors: true
    #provisionedConcurrency: 5
  postgraphsettings:
    handler: AwsDotnetCsharp::PMF.GraphSettingsPost::PostGraphSettings
    events:
      - http:
          path: postgraphsettings
          method: post
          cors: true
    #provisionedConcurrency: 5
  postIveriLiteTransaction:
    handler: AwsDotnetCsharp::PMF.RecordPaymentTransaction::PostIveriLiteTransaction
    events:
      - http:
          path: postiveritransaction
          method: post
          cors: true
    timeout: 30  
  iVeriPayment:
    handler: AwsDotnetCsharp::PMF.RedirectIveriPayment::IVeriPayment
    events:
      - http:
          path: iveripayment
          method: post
          cors: true
    timeout: 45  
    #provisionedConcurrency: 5
  generateReceipt:
    handler: AwsDotnetCsharp::PMF.RedirectIveriPayment::GenerateReceipt
    events:
      - http:
          path: generatereceipt
          method: post
          cors: true
    timeout: 45
  contactUs:
    handler: AwsDotnetCsharp::PMF.ContactUs::ContactUsInformation
    events:
      - http:
          path: contactUs
          method: post
          cors: true
    timeout: 45      
    #provisionedConcurrency: 5
  RunCronJob:
     handler: AwsDotnetCsharp::PMF.CronJob::RunCronJob
     events:
        - http:
            path: runcronjob
            method: get
            cors: true
        #  authorizer: aws_iam
        - schedule:
            name: RunCronJobDev
            description: 'run the cronjob every 8 hours'
        #     we can use cron expressions here should we require the cron to run on certain days.
        #     schedule: cron(0 18 * * ? *) ---> use this to run the cron everyday at 6pm
            rate: rate(2 hours)      # --> use this for every 8 hours recommended  2 hours for testing
     timeout: 900
