github.com/cloudwan/edgelq-sdk@v1.15.4/cellular-api/resources/v1/sim_card_stock/sim_card_stock.pb.name.go (about) 1 // Code generated by protoc-gen-goten-resource 2 // Resource: SimCardStock 3 // DO NOT EDIT!!! 4 5 package sim_card_stock 6 7 import ( 8 "fmt" 9 "net/url" 10 "reflect" 11 "regexp" 12 "strings" 13 14 "google.golang.org/grpc/codes" 15 "google.golang.org/grpc/status" 16 "google.golang.org/protobuf/proto" 17 18 "github.com/cloudwan/goten-sdk/runtime/goten" 19 gotenresource "github.com/cloudwan/goten-sdk/runtime/resource" 20 ) 21 22 // proto imports 23 import ( 24 contract "github.com/cloudwan/edgelq-sdk/cellular-api/resources/v1/contract" 25 sim_card "github.com/cloudwan/edgelq-sdk/cellular-api/resources/v1/sim_card" 26 meta "github.com/cloudwan/goten-sdk/types/meta" 27 ) 28 29 // ensure the imports are used 30 var ( 31 _ = codes.NotFound 32 _ = new(fmt.Stringer) 33 _ = new(proto.Message) 34 _ = status.Status{} 35 _ = url.URL{} 36 _ = strings.Builder{} 37 38 _ = new(goten.GotenMessage) 39 _ = new(gotenresource.ListQuery) 40 ) 41 42 // make sure we're using proto imports 43 var ( 44 _ = &contract.Contract{} 45 _ = &sim_card.SimCard{} 46 _ = &meta.Meta{} 47 ) 48 49 var simCardStock_RegexpId = regexp.MustCompile("^(?P<sim_card_stock_id>\\d{19})$") 50 var regexPath = regexp.MustCompile("^simCardStocks/(?P<sim_card_stock_id>-|\\d{19})$") 51 52 func (r *SimCardStock) MaybePopulateDefaults() error { 53 simCardStockInterface := interface{}(r) 54 if defaulter, ok := simCardStockInterface.(goten.Defaulter); ok { 55 return defaulter.PopulateDefaults() 56 } 57 return nil 58 } 59 60 type Name struct { 61 NamePattern 62 SimCardStockId string `firestore:"simCardStockId"` 63 } 64 65 func ParseName(name string) (*Name, error) { 66 var matches []string 67 if matches = regexPath.FindStringSubmatch(name); matches != nil { 68 return NewNameBuilder(). 69 SetId(matches[1]). 70 Name(), nil 71 } 72 73 return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as SimCardStock name", name) 74 } 75 76 func MustParseName(name string) *Name { 77 result, err := ParseName(name) 78 if err != nil { 79 panic(err) 80 } 81 return result 82 } 83 84 func ParseNameOrId(nameOrId string) (*Name, error) { 85 name, err := ParseName(nameOrId) 86 if err == nil { 87 return name, err 88 } 89 if simCardStock_RegexpId.MatchString(nameOrId) { 90 return &Name{SimCardStockId: nameOrId}, nil 91 } else { 92 return nil, fmt.Errorf("unable to parse '%s' as SimCardStock name or id", nameOrId) 93 } 94 } 95 96 func (name *Name) SetFromSegments(segments gotenresource.NameSegments) error { 97 if len(segments) == 0 { 98 return status.Errorf(codes.InvalidArgument, "No segments given for SimCardStock name") 99 } 100 if segments[len(segments)-1].CollectionLowerJson != "simCardStocks" { 101 return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form SimCardStock name", segments) 102 } 103 name.Pattern = NamePattern_Nil 104 name.SimCardStockId = segments[len(segments)-1].Id 105 return nil 106 } 107 108 func (name *Name) IsSpecified() bool { 109 if name == nil || name.Pattern == "" || name.SimCardStockId == "" { 110 return false 111 } 112 return name.Pattern == NamePattern_Nil 113 } 114 115 func (name *Name) IsFullyQualified() bool { 116 if name == nil { 117 return false 118 } 119 if name.SimCardStockId == "" || name.SimCardStockId == gotenresource.WildcardId { 120 return false 121 } 122 return true 123 } 124 125 func (name *Name) FullyQualifiedName() (string, error) { 126 if !name.IsFullyQualified() { 127 return "", status.Errorf(codes.InvalidArgument, "Name for SimCardStock is not fully qualified") 128 } 129 return fmt.Sprintf("//cellular-api.edgelq.com/%s", name.String()), nil 130 } 131 132 func (name *Name) String() string { 133 if name == nil { 134 return "<nil>" 135 } 136 if valueStr, err := name.ProtoString(); err != nil { 137 panic(err) 138 } else { 139 return valueStr 140 } 141 } 142 143 func (name *Name) AsReference() *Reference { 144 return &Reference{Name: *name} 145 } 146 147 func (name *Name) AsRawReference() gotenresource.Reference { 148 return name.AsReference() 149 } 150 151 func (name *Name) GetResourceDescriptor() gotenresource.Descriptor { 152 return descriptor 153 } 154 155 func (name *Name) GetPattern() gotenresource.NamePattern { 156 if name == nil { 157 return "" 158 } 159 return name.Pattern 160 } 161 162 func (name *Name) GetIdParts() map[string]string { 163 if name != nil { 164 return map[string]string{ 165 "simCardStockId": name.SimCardStockId, 166 } 167 } 168 return map[string]string{ 169 "simCardStockId": "", 170 } 171 } 172 173 func (name *Name) GetSegments() gotenresource.NameSegments { 174 if name == nil || name.Pattern == "" { 175 return nil 176 } 177 return gotenresource.NameSegments{{ 178 CollectionLowerJson: "simCardStocks", 179 Id: name.SimCardStockId, 180 }} 181 } 182 183 func (name *Name) GetIParentName() gotenresource.Name { 184 return nil 185 } 186 187 func (name *Name) GetIUnderlyingParentName() gotenresource.Name { 188 return nil 189 } 190 191 // implement methods required by protobuf-go library for string-struct conversion 192 193 func (name *Name) ProtoString() (string, error) { 194 if name == nil { 195 return "", nil 196 } 197 result := "" 198 result += "simCardStocks/" + name.SimCardStockId 199 return result, nil 200 } 201 202 func (name *Name) ParseProtoString(data string) error { 203 parsed, err := ParseName(data) 204 if err != nil { 205 return err 206 } 207 *name = *parsed 208 return nil 209 } 210 211 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 212 func (name *Name) GotenEqual(other interface{}) bool { 213 if other == nil { 214 return name == nil 215 } 216 other1, ok := other.(*Name) 217 if !ok { 218 other2, ok := other.(Name) 219 if ok { 220 other1 = &other2 221 } else { 222 return false 223 } 224 } 225 if other1 == nil { 226 return name == nil 227 } else if name == nil { 228 return false 229 } 230 if name.SimCardStockId != other1.SimCardStockId { 231 return false 232 } 233 234 return true 235 } 236 237 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 238 func (name *Name) Matches(other interface{}) bool { 239 if other == nil { 240 return name == nil 241 } 242 other1, ok := other.(*Name) 243 if !ok { 244 other2, ok := other.(Name) 245 if ok { 246 other1 = &other2 247 } else { 248 return false 249 } 250 } 251 if other1 == nil { 252 return name == nil 253 } else if name == nil { 254 return false 255 } 256 if name.SimCardStockId != other1.SimCardStockId { 257 return name.SimCardStockId == gotenresource.WildcardId 258 } 259 260 return true 261 } 262 263 // implement CustomTypeCliValue method 264 func (name *Name) SetFromCliFlag(raw string) error { 265 parsedName, err := ParseName(raw) 266 if err != nil { 267 return err 268 } 269 *name = *parsedName 270 return nil 271 } 272 273 type Reference struct { 274 Name 275 simCardStock *SimCardStock 276 } 277 278 func MakeReference(name *Name, simCardStock *SimCardStock) (*Reference, error) { 279 return &Reference{ 280 Name: *name, 281 simCardStock: simCardStock, 282 }, nil 283 } 284 285 func ParseReference(name string) (*Reference, error) { 286 parsedName, err := ParseName(name) 287 if err != nil { 288 return nil, err 289 } 290 return MakeReference(parsedName, nil) 291 } 292 293 func MustParseReference(name string) *Reference { 294 result, err := ParseReference(name) 295 if err != nil { 296 panic(err) 297 } 298 return result 299 } 300 301 func (ref *Reference) Resolve(resolved *SimCardStock) { 302 ref.simCardStock = resolved 303 } 304 305 func (ref *Reference) ResolveRaw(res gotenresource.Resource) error { 306 if res == nil { 307 ref.Resolve(nil) 308 return nil 309 } 310 if typedRes, ok := res.(*SimCardStock); ok { 311 ref.Resolve(typedRes) 312 return nil 313 } 314 return status.Errorf(codes.Internal, "Invalid resource type for SimCardStock: %s", reflect.TypeOf(res).Elem().Name()) 315 } 316 317 func (ref *Reference) Resolved() bool { 318 return ref != nil && ref.simCardStock != nil 319 } 320 321 func (ref *Reference) ClearCached() { 322 ref.simCardStock = nil 323 } 324 325 func (ref *Reference) GetSimCardStock() *SimCardStock { 326 if ref == nil { 327 return nil 328 } 329 return ref.simCardStock 330 } 331 332 func (ref *Reference) GetRawResource() gotenresource.Resource { 333 if ref == nil { 334 return (*SimCardStock)(nil) 335 } 336 return ref.simCardStock 337 } 338 339 func (ref *Reference) IsFullyQualified() bool { 340 if ref == nil { 341 return false 342 } 343 return ref.Name.IsFullyQualified() 344 } 345 346 func (ref *Reference) IsSpecified() bool { 347 if ref == nil { 348 return false 349 } 350 return ref.Name.IsSpecified() 351 } 352 353 func (ref *Reference) FullyQualifiedName() (string, error) { 354 if !ref.IsFullyQualified() { 355 return "", status.Errorf(codes.InvalidArgument, "Name for SimCardStock is not fully qualified") 356 } 357 return fmt.Sprintf("//cellular-api.edgelq.com/%s", ref.String()), nil 358 } 359 360 func (ref *Reference) GetResourceDescriptor() gotenresource.Descriptor { 361 return descriptor 362 } 363 364 func (ref *Reference) GetPattern() gotenresource.NamePattern { 365 if ref == nil { 366 return "" 367 } 368 return ref.Pattern 369 } 370 371 func (ref *Reference) GetIdParts() map[string]string { 372 if ref != nil { 373 return ref.Name.GetIdParts() 374 } 375 return map[string]string{ 376 "simCardStockId": "", 377 } 378 } 379 380 func (ref *Reference) GetSegments() gotenresource.NameSegments { 381 if ref != nil { 382 return ref.Name.GetSegments() 383 } 384 return nil 385 } 386 387 func (ref *Reference) GetIParentName() gotenresource.Name { 388 return nil 389 } 390 391 func (ref *Reference) GetIUnderlyingParentName() gotenresource.Name { 392 if ref != nil { 393 return ref.Name.GetIUnderlyingParentName() 394 } 395 return nil 396 } 397 398 func (ref *Reference) String() string { 399 if ref == nil { 400 return "<nil>" 401 } 402 return ref.Name.String() 403 } 404 405 // implement methods required by protobuf-go library for string-struct conversion 406 407 func (ref *Reference) ProtoString() (string, error) { 408 if ref == nil { 409 return "", nil 410 } 411 return ref.Name.ProtoString() 412 } 413 414 func (ref *Reference) ParseProtoString(data string) error { 415 parsed, err := ParseReference(data) 416 if err != nil { 417 return err 418 } 419 *ref = *parsed 420 return nil 421 } 422 423 // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface) 424 func (ref *Reference) GotenEqual(other interface{}) bool { 425 if other == nil { 426 return ref == nil 427 } 428 other1, ok := other.(*Reference) 429 if !ok { 430 other2, ok := other.(Reference) 431 if ok { 432 other1 = &other2 433 } else { 434 return false 435 } 436 } 437 if other1 == nil { 438 return ref == nil 439 } else if ref == nil { 440 return false 441 } 442 443 return ref.Name.GotenEqual(other1.Name) 444 } 445 446 // Matches is same as GotenEqual, but also will accept "other" if name is wildcard. 447 func (name *Reference) Matches(other interface{}) bool { 448 if other == nil { 449 return name == nil 450 } 451 other1, ok := other.(*Reference) 452 if !ok { 453 other2, ok := other.(Reference) 454 if ok { 455 other1 = &other2 456 } else { 457 return false 458 } 459 } 460 if other1 == nil { 461 return name == nil 462 } else if name == nil { 463 return false 464 } 465 return name.Name.Matches(&other1.Name) 466 } 467 468 // implement CustomTypeCliValue method 469 func (ref *Reference) SetFromCliFlag(raw string) error { 470 parsedRef, err := ParseReference(raw) 471 if err != nil { 472 return err 473 } 474 *ref = *parsedRef 475 return nil 476 }