Created
January 15, 2022 02:36
-
-
Save GeekTree0101/3855ba338869ab50cae047febddbca21 to your computer and use it in GitHub Desktop.
TheProgrammersBrain34page.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum CouponStatus { | |
case notExist | |
case retry | |
case expired | |
case active | |
case get | |
case used | |
case usable | |
} | |
struct Coupon { | |
let user: UserCoupon? | |
let isActive: Bool | |
let expiredDate: Date | |
} | |
struct UserCoupon { | |
let isUsed: Bool | |
} | |
func status(isOwner: Bool?, coupon: Coupon?) -> CouponStatus { | |
guard let isOwner = isOwner, let coupon = coupon else { | |
return .notExist | |
} | |
let currentDate = Date() | |
if isOwner { | |
if !coupon.isActive { | |
return .retry | |
} | |
if !(currentDate < coupon.expiredDate) { | |
return .expired | |
} | |
return .active | |
} else { | |
if !coupon.isActive { | |
return .retry | |
} | |
if !(currentDate < coupon.expiredDate) { | |
return .expired | |
} | |
if coupon.user == nil { | |
return .get | |
} | |
if coupon.user?.isUsed == true { | |
return .used | |
} | |
return .usable | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment