---
# System prepended metadata

title: Unlock Design Session

---

# Unlock Design Session

Goal: API Calls and DB Tables to capture the Submit -> Unlock -> Re-submit flow
Secondary Goal: Consider CMS users viewing old submissions


Decisions
* Probably want to add UnlockedSubmission state
* Unlocked by... and ResubmittedBy... belong on the new revision
* Revision and Package tables should be separate. 


## Actions

### State User — initial submit
- sets `submittedAt`
- should probably set `submittedBy`


### CMS User — unlock
- "Reason For Unlocking Submission"
- "Unlocked By"
- "Unlocked On" (date)


### State User — resubmit - update, re-lock, return for comments
- "Updated On" (date)
- "Changes Made"
- "Updated By"?



Old Version

Revision 1 submitted on jan 1
- submittedat / By

Unlocked on jan 3

Revision 2 resubmitted on jan 5
- unlocked at/by/reason
- submitted at/by/reason

Unlocked again on jan 10

Revision 3 resubmmitted on jan 15
- unlocked at/by/reason
- submitted at/by/reason




CMS WORKFLOW

This is an action, that we want to record


## States
- INITIAL_DRAFT
- INITIAL_SUBMIT
- UNLOCKED_DRAFT
- RESUBMITTED



## Data

### Postgres Schema

```
model MCReviewPackage BUndle
model StateSubmission {
  id                  String @id
  state               State  @relation(fields: [stateCode], references: [stateCode])
  stateCode           String
  --submissionFormProto Bytes
}

model StateSubmissionRevision {
  id                  String @id
  submission          Submission @relation()
  submissionID        String
  
  unlockedAt
  unlockedBy
  unlockReason
  
  resubmittedAt
  resubmittedBy
  resubmittedReason
  
  submissionFormProto Bytes
}


model Actions {
    id
    timestamp        Time
    actor            email? link 
    message          string
    submission        stateSubmission
    submissionID
    

}

model Review {
    Status. [Submitted, OACT Aproval, Final Letter Approved]
    DMCO Reviewers
    OACT Reviewers

}


model State {
  stateCode                   String            @id
  name                        String
  latestStateSubmissionNumber Int               @default(0)
  stateSubmissions            StateSubmission[]
}

```

Review State Machine
- submitted
- questions asked
- questions answered
- remediation required?
- OACT approves
- Final Letter sent



**Package Table**
| id        | submittedAt | stateCode | Status   |
| --------- | ----------- | --------- | -------- |
| 1111-aaaa | 2020-01-02  | VA        | UNLOCKED |
| 2222-bbbb | null        | VA        | DRAFT    |
| 3333-cccc | 2021-02-01  | FL        | LOCKED   |
| 4444-dddd | null        | VA.       | DRAFT    |


**PackageRevision Table**
| id        | lockedAt   | rev | submissionID | submissionFormProto |
| --------- | ---------- | --- | ------------ | ------------------- |
| aaaa-9999 | 2020-03-04 | 0   | 4444-dddd    | _binary data_       |
| bbbb-9999 | null       | 1   | 4444-dddd    | _binary data_       |
| cccc-9999 | null       | 0   | 1111-aaaa    | _binary data_       |
| dddd-9999 | 2021-02-01 | 0   | 2222-bbbb    | _binary data_       |
| eeee-9999 | null       | 0   | 3333-cccc    | _binary data_       |

---


**SingleTableVersion**
| id        | lockedAt   | rev | stateCode | submissionID | submissionFormProto |
| --------- | ---------- | --- | --------- | ------------ | ------------------- |
| aaaa-9999 | 2020-03-04 | 0   | VA        | 4444-dddd    | _binary data_       |
| bbbb-9999 | null       | 1   | VA        | 4444-dddd    | _binary data_       |
| cccc-9999 | null       | 0   | VA        | 1111-aaaa    | _binary data_       |
| dddd-9999 | 2021-02-01 | 0   | FL        | 2222-bbbb    | _binary data_       |
| eeee-9999 | null       | 0   | VA        | 3333-cccc    | _binary data_       |

DRAFT {

}

INITIAL_LOCKED {

    submittedAt


}


UNLOCKED {
  submittedAt
  
  unlockedAt
  unlockedBy
  unlockReason

}

LOCKED {
  submittedAt
  
  unlockedAt
  unlockedBy
  unlockReason
  
  resubmittedAt
  resubmittedBy
  resubmittedReason

}




### Submission Protobuf Schema


```
message StateSubmissionInfo {
  optional string proto_name = 1;
  optional int32 proto_version = 2;
  
  // Metadata
  optional string id = 3;
  optional string status = 4; // DRAFT | LOCKED | UNLOCKED
  optional Date created_at = 5;
  optional google.protobuf.Timestamp updated_at = 6; // changes every time we call updateDraftSubmission
  optional google.protobuf.Timestamp submitted_at = 7;
  
  optional SubmissionStatus submission_status = 8; // whoops this isn't being used...
  
  optional StateCode state_code = 9;
  optional int32 state_number = 10;
  
  // The actual submission info
  repeated string program_ids = 11;
  optional SubmissionType submission_type = 12;
  optional string submission_description = 13;
  repeated Contact state_contacts = 14;
  optional ContractInfo contract_info = 15;
  repeated Document documents = 16;
  repeated RateInfo rate_infos = 50;
}
```

## API

```
schema {
    query: Query
    mutation: Mutation
}

type Query {
    fetchCurrentUser
    fetchDraftSubmission
    fetchStateSubmission

    indexSubmissions
}

type Mutation {
    createDraftSubmission
    updateDraftSubmission
    updateUnlockedSubmission?
    submitDraftSubmission
    resubmitUnlockedSubmission?
}

input FetchDraftSubmissionInput {
    submissionID: ID!
}

type FetchDraftSubmissionPayload {
    draftSubmission: DraftSubmission
}

//NEW
type FetchUnlockedSubmissionPayload {
    submissionPackage: DraftSubmission
    unlockedAt:
    unlockedBy:
    unlockedMessage:
}

input FetchStateSubmissionInput {
    submissionID: ID!
}

type FetchStateSubmissionPayload {
    submission: StateSubmission
}

type SubmissionEdge {
    node: Submission!
}

type IndexSubmissionsPayload {
    totalCount: Int
    edges: [SubmissionEdge!]!
}

input UpdateDraftSubmissionInput {
    submissionID: ID!
    draftSubmissionUpdates: DraftSubmissionUpdates!
}

type UpdateDraftSubmissionPayload {
    draftSubmission: DraftSubmission!
}

input SubmitDraftSubmissionInput {
    submissionID: ID!
}

type SubmitDraftSubmissionPayload {
    submission: StateSubmission!
}


type State {
    code: String!
    name: String!
    programs: [Program!]!
}

type DraftSubmission {
    id: ID!
    status: DRAFT | UNLOCKED
    
    // elide if UnlockedSubmission is a thing
    submittedAt
    unlockedAt
    unlockedBy
    unlockedMessage
    
    
    programID: String!
    program: Program!
    submissionType: SubmissionType!
    submissionDescription: String!
    stateCode: String!
    name: String!
    
    createdAt: Date!
    updatedAt: DateTime!
    
    ...
}

type UnlockedSubmission {
    id: ID!
    status: UNLOCKED
    
    submittedAt
    unlockedAt
    unlockedBy
    unlockedMessage
    
    
    programID: String!
    program: Program!
    submissionType: SubmissionType!
    submissionDescription: String!
    stateCode: String!
    name: String!
    
    createdAt: Date!
    updatedAt: DateTime!
    
    ...
}

type LockedSubmission {
    id: ID!
    status: LOCKED
    
    submittedAt
    unlockedAt
    unlockedBy
    unlockedMessage
    
    lockedAt
    lockedBy
    lockedMessage
    
    programID: String!
    program: Program!
    submissionType: SubmissionType!
    submissionDescription: String!
    stateCode: String!
    name: String!
    
    createdAt: Date!
    updatedAt: DateTime!
    submittedAt: Date!
    
    ...
}

union Submission = DraftSubmission | StateSubmission

input DraftSubmissionUpdates {
    programID: String!
    submissionType: SubmissionType!
    submissionDescription: String!
    ...
}

```