# Contract + Rates History
* Is there a parent type? Some container with contracts and rates?
* is that a Submission
* Submission Revision?
* submissiontype: has contract and rate types.
* when you. make a new submission, it's part of the overall submission thing
## How to represent histories in the domain models
### ideas for new top level types
* Submission Container Type
* Contract1 + Rate1 + Rate2
* resubmitting rate1 adds a submission revision to this container
* unlinking rate2 adds a submission revision to this container
* Is this a db level concept?
* Feels like we are overloading the join table
* Sumbit: c0,r1,r2
* Unlock: c0.1, r1, r2
* Resubmit: c0.1, r1, r2
* ResubmitRate: c0.1, r1.1, r2
* UnlinkRate: c0.1, r.1., REMOVE r2
### ideas for new fields on the contract/rate type
* Add HISTORY field that replaces the revisions field, we compute based on the join table with the submitInfos.
* More details on his [hackmd](https://hackmd.io/vTHI_MUfSL-ke03Qy0WzAw?both)
* history has both contractrev entries and raterev entries.
* one place that has rate rev and contract rev is good
* changes domain model only
* How can you tell if a rate is unlinked?
* it would be in the history, but it's contracts wouldn't include this contract? seems complicated
* Jason has a doc on this https://docs.google.com/document/d/1hvP0axqGZJOKB0HarvzJW5iNQozNWyZbZtoz_axrhw8/edit
* Add new table recording submission history events. This becomes new field on contract/rate. When the rate gets unlinked, that would be a new entry in the shared table.
* THere's a table that is the history of a given contract or rate, each entry is a line item in that table
* contractID, action: linkng | unlinking, rateID
* Submission: contract + rate + rate + rate
* changes domain model and database
* new submissionHistory: SubmitInfo[] field
* collect related submit infos for this type, including a submit info where a rate is unlinked
* Add actionLog field
* values like: SubmitContract, LinkRate, etc
* changes to database and domain model
* Very explicit, easier to reason about
## Migrations?
* do we have the data we need in general?
* We dont have a way to say these contract and rates were submitted as part of the same submission
* Figuring out the domain model solution with the current data model would mean no migration which woudl be chill.
## General
* whatedver we do we'd better document exactly how these things are constructed.
* Q: Does Rate History include the same level of detail for the contract?
```
ContractActionType: SubmitContract, UnlockContract, UpdateRate, UnlinkRate, LinkRate
RateActionType: SubmitRate, UnlockRate, UpdateContract, UnlinkContract, LinkContract
(submission + action): here's the submission and it was a RateUpdate or a LinkRate
Submission:
ThingSubmitted: RateRevision | ContractRevision
RelatedThigns: ContractRevision[] | RateRevision[]
THINGS: (RateRevision | ContractRevision)[]
type ContractType = {
id: string;
status: "SUBMITTED" | "DRAFT" | "UNLOCKED" | "RESUBMITTED";
stateCode: string;
stateNumber: number;
mccrsID: string | undefined,
draftRevision: ContractRevisionWithRatesType
actionLog: ActionType[],
submissionHistory: submitInfo[]
history: (ContractRevisionWithRatesType | RateRevisionWithContractType)[],
revisions: ContractRevisionWithRatesType[] {
id: string;
contract: {
stateCode: string;
id: string;
stateNumber: number;
};
submitInfo: UpdateInfoType | undefined,
unlockInfo: UpdateInfoType | undefined,
createdAt: Date,
updatedAt: Date,
formData: ContractFormDataType,
rateRevisions: RateRevisionType[]
}[]
}
type RateType = {
id: string;
status: "SUBMITTED" | "DRAFT" | "UNLOCKED" | "RESUBMITTED";
stateCode: string;
stateNumber: number;
mccrsID: string | undefined,
draftRevision: RateRevisionWithContractsType
revisions: RateRevisionWithContractsType[] {
id: string;
rate: {
stateCode: string;
id: string;
stateNumber: number;
createdAt: Date;
};
submitInfo: UpdateInfoType | undefined,
unlockInfo: UpdateInfoType | undefined,
createdAt: Date,
updatedAt: Date,
formData: RateFormDataType,
}
contractRevisions: ContractRevisionType[]
}
```
Example of adding "submissions" to Contract+Rate
```
ContractA = {
id
status
stateCode
mccrsID
stateNumber
draftRevision
revisions: [
{ //A.0
id
submitInfo
unlockInfo
formData
},
{ //A.1
id
submitInfo
unlockInfo
formData
}
],
submissionHistory: [
{
updatedRev: Contract | Rate
contractRev: ContractRev
rateRevs: RateRev[]
}
]
submissions: [
{ // ContractA.0
updatedAt
updateReason
updatedBy
contractRevision: { // A.0
id
formData
rateRevisions: [
{...}, // Rate1.0
{...}, // Rate2.0
]
}
rateRevisions: [
{// Rate1.0
id
formData
contractRevisions: [
{...}// ContractA.0
]
},
{// Rate2.0
id
formData
contractRevisions: [
{...}// ContractA.0
]
},
]
},
{ // Rate1.1
updatedAt
updateReason
updatedBy
contractRevision: undefined
rateRevisions: [
{// Rate1.1
id
formData
contractRevisions: [
{...}// ContractA.0
]
},
]
},
{ // ContractA.1
updatedAt
updateReason
updatedBy
contractRevision: { // A.1
id
formData
rateRevisions: [
{...}, // Rate1.1
{...}, // Rate2.0
]
}
rateRevisions: []
}
]
}
Rate2 = {
id
status
stateCode
stateNumber
draftRevision
draftContracts
revisions: [
{ //2.0
id
submitInfo
unlockInfo
formData
},
],
submissionHistory: [
{
updatedRev: (ContractRev | RateRev)[]
rateRev: RateRev
contractRevs: ContractRev[]
}
]
submissions: [
{ // ContractA.0
updatedAt
updateReason
updatedBy
contractRevision: { // A.0
id
formData
rateRevisions: [
{...}, // Rate1.0
{...}, // Rate2.0
]
},
rateRevisions: [
{// Rate1.0
id
formData
contractRevisions: [
{...}// ContractA.0
]
},
{// Rate2.0
id
formData
contractRevisions: [
{...}// ContractA.0
]
},
]
},
{ // ContractC.0
updatedAt
updateReason
updatedBy
contractRevision: { // C.0
id
formData
rateRevisions: [
{// Rate4.0
id
formData
contractRevisions: [
{...}// ContractC.0
]
},
{// Rate2.0
id
formData
contractRevisions: [
{...}// ContractA.0,
{...}// ContractC.0,
]
},
]
}
},
{ // ContractA.1
updatedAt
updateReason
updatedBy
contractRevision: { // A.1
id
formData
rateRevisions: [
{...}, // Rate1.1
{...}, // Rate2.0
]
}
rateRevisions: []
}
{ // ContractC.1
updatedAt
updateReason
updatedBy
contractRevision: {...} // C.1
rateRevisions: []
}
]
}
```
* This doesn't really let us construct the snapshots we want in rate history, really.
* The removal especially is confusing, we'd need to see how rateRevisions are set?
* What I actually want is "snapshot of _____ at time of x submission"